Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > Mobile > Mobile Forum > iOS - ช่วยด้วยครับ แอดไปหน้า Favorite พอปิด iOS Simulator แล้วเปิดใหม อยากไห้มีข้อมูล หน้า Favorite เหมือนตอนแอดครับ!!



 

iOS - ช่วยด้วยครับ แอดไปหน้า Favorite พอปิด iOS Simulator แล้วเปิดใหม อยากไห้มีข้อมูล หน้า Favorite เหมือนตอนแอดครับ!!

 



Topic : 097726



โพสกระทู้ ( 20 )
บทความ ( 0 )



สถานะออฟไลน์




ช่วยหน่อยครับ ท่านผู้รู้ พอดีผมกำลังทำ เกี่ยวกับ Favorite แต่ปัญหาคือ เวลาแอดเป็น Favorite แล้ว ปิด iOS Simulator เริ่มใหม่หมด หน้าที่เพิ่งแอดเป็น Favorite ก็ หายไป พอมีวิธีใหมครับ หรือว่าต้องลองกับเครืื่องจริง!!

โค้คทั้งหมดครับ


AppDelegate.h
Code (Objective-C)
#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (nonatomic,strong) NSMutableArray *friendArray_Delegate;
@end


AppDelegate.m
Code (Objective-C)
#import "AppDelegate.h"
#import "Friends.h"

@implementation AppDelegate


-(void)setdata
{
    self.friendArray_Delegate = [[NSMutableArray alloc]init];
    
    [self.friendArray_Delegate addObject:[[Friends alloc]initWithName:@"Onepen" andPhoneNo:@"081000000" andImageName:[UIImage imageNamed:@"1.jpg"]]];
    [self.friendArray_Delegate addObject:[[Friends alloc]initWithName:@"Twopen" andPhoneNo:@"082000000" andImageName:[UIImage imageNamed:@"3.jpg"]]];
    [self.friendArray_Delegate addObject:[[Friends alloc]initWithName:@"Threepen" andPhoneNo:@"08300000" andImageName:[UIImage imageNamed:@"4.jpeg"] ]];
    [self.friendArray_Delegate addObject:[[Friends alloc]initWithName:@"Fourpen" andPhoneNo:@"084000000" andImageName:[UIImage imageNamed:@"5.jpg" ]]];
    [self.friendArray_Delegate addObject:[[Friends alloc]initWithName:@"Fivepen" andPhoneNo:@"0855555555" andImageName:[UIImage imageNamed:@"6.jpg"] ]];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [self setdata];
    // Override point for customization after application launch.
    return YES;
}
							
- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end






Friends.h
Code (Objective-C)
#import <Foundation/Foundation.h>

@interface Friends : NSObject
@property (nonatomic, strong)NSString *name;
@property (nonatomic, strong)NSString *phone;
@property (nonatomic, strong)UIImage *image;
@property (nonatomic, assign)BOOL favorite;
-(id)initWithName:(NSString *)tempName andPhoneNo:(NSString *)tempPhoneNo andImageName:(UIImage *)tempImage;
@end





Friends.m
Code (Objective-C)
#import "Friends.h"

@implementation Friends
-(id)initWithName:(NSString *)tempName andPhoneNo:(NSString *)tempPhoneNo andImageName:(UIImage *)tempImage
{
    
    self = [super init];
    if(self){
        self.name = tempName;
        self.phone = tempPhoneNo;
        self.image = tempImage;
        self.favorite = NO;
    }
    return self;
}
@end





FirstViewController.h

Code (Objective-C)
#import <UIKit/UIKit.h>

@interface FirstViewController : UIViewController <UITableViewDataSource,UITableViewDelegate>

@property (strong, nonatomic) IBOutlet UITableView *tableView;

@property (strong,nonatomic) NSMutableArray *friendArray_First;

@end




FirstViewController.h

Code (Objective-C)
#import "FirstViewController.h"
#import "AppDelegate.h"
#import "Friends.h"
#import "ChannelViewController.h"

@interface FirstViewController ()

@end

@implementation FirstViewController
-(AppDelegate*) appDelegate
{
    return (AppDelegate *)[[UIApplication sharedApplication]delegate];
}



- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    self.friendArray_First = [[NSMutableArray alloc]init];
    self.friendArray_First = [self appDelegate].friendArray_Delegate;
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    
    [self.tableView reloadData];
}


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
      
    }
    return self;
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}




- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.friendArray_First.count;
    
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    //กำหนดว่ามีกี่ section(กลุ่ม)
    
    return 1;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    //จัดการกับข้อมูลแต่ละ cell
    //มันเหมือนวน loop ใส่ข้อความไปแต่ละรอบ
    
    static NSString * CellIdentifier = @"Cell";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if(cell == nil){
    
        
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }
    
    Friends *obj = [self.friendArray_First objectAtIndex:indexPath.row];
    cell.accessoryType=UITableViewCellAccessoryDetailDisclosureButton; //เพิ่มปุ่มButton
    cell.textLabel.text = [obj name];
    cell.detailTextLabel.text = [obj phone];
    
    
    cell.imageView.image = obj.image;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
           
    ChannelViewController *detailv = [[ChannelViewController alloc]initWithfriend:[self.friendArray_First objectAtIndex:indexPath.row]];
    [self.navigationController pushViewController:detailv animated:YES];

    
}



@end




ChannelViewController.h

Code (Objective-C)
#import <UIKit/UIKit.h>
#import "Friends.h"

@interface ChannelViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIImageView *pic1;
@property (strong, nonatomic) IBOutlet UILabel *name;
@property (strong, nonatomic) IBOutlet UILabel *phone;

@property(nonatomic,strong)Friends *detailf;

-(id)initWithfriend:(Friends *)tempfriends;
@end




ChannelViewController.m
Code (Objective-C)
#import "ChannelViewController.h"
#import "AppDelegate.h"

@interface ChannelViewController ()

@end

@implementation ChannelViewController

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}


-(AppDelegate*) appDelegate
{
    return (AppDelegate *)[[UIApplication sharedApplication]delegate];
}


-(void)addfaverite
{
    if(self.detailf.favorite == NO)
    {
        self.detailf.favorite = YES;
    }
    else self.detailf.favorite = NO;
    
    
    
}






-(id)initWithfriend:(Friends *)tempfriends
{
    self = [super initWithNibName:@"ChannelViewController" bundle:nil];
    if (self) {
        // Custom initialization
        self.detailf = tempfriends;
        
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
   
    
    self.name.text = self.detailf.name;
    
    self.phone.text = self.detailf.phone;
    self.pic1.image = self.detailf.image;
    
    
    
    
    UIBarButtonItem *lbarbutton = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"28-star.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(addfaverite)];
    self.navigationItem.rightBarButtonItem = lbarbutton;
    
}




FavoriteViewController.h

Code (Objective-C)
#import <UIKit/UIKit.h>

@interface FavoriteViewController : UIViewController<UITabBarControllerDelegate,UITableViewDataSource>
@property (strong, nonatomic) IBOutlet UITableView *Tablef;
@property (strong,nonatomic) NSMutableArray *favArray;
@end


FavoriteViewController.m
Code (Objective-C)
#import "FavoriteViewController.h"
#import "ChannelViewController.h"
#import "AppDelegate.h"

@interface FavoriteViewController ()

@end

@implementation FavoriteViewController




-(AppDelegate*) appDelegate
{
    return (AppDelegate *)[[UIApplication sharedApplication]delegate];
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    self.favArray =[[NSMutableArray alloc]init];
    
    
    for (Friends *i in [self appDelegate].friendArray_Delegate) {
        if (i.favorite) {
            [self.favArray addObject:i];
        }
    }
    [self.Tablef reloadData];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}





- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.favArray.count;
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    //กำหนดว่ามีกี่ section(กลุ่ม)
    
    return 1;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    //จัดการกับข้อมูลแต่ละ cell
    //มันเหมือนวน loop ใส่ข้อความไปแต่ละรอบ
    
    static NSString * CellIdentifier = @"Cell";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if(cell == nil){

        
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }
    
    Friends *obj = [self.favArray objectAtIndex:indexPath.row];
    cell.accessoryType=UITableViewCellAccessoryDetailDisclosureButton;
    cell.textLabel.text = [obj name];
    cell.detailTextLabel.text = [obj phone];
    
    
    cell.imageView.image = obj.image;
    
    
    return cell;
}


@end




ส่วนนี้ตัวโค้ค ทั้งหมดครับ เพื่อลอง Run
http://www.filecondo.com/download_regular.php?file=k143a81uXwPn



Tag : Mobile, iOS







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2013-07-12 13:34:22 By : iMonster View : 1718 Reply : 3
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

ลอง Capture ภาพประกอบด้วยครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-07-12 16:23:42 By : mr.win
 


 

No. 2



โพสกระทู้ ( 20 )
บทความ ( 0 )



สถานะออฟไลน์


ขอบคุณครับ พอเข้าใจละ อิอิ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-07-16 09:29:31 By : iMonster
 

 

No. 3



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

ยังไงหว๋า
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-07-16 16:22:50 By : mr.win
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : iOS - ช่วยด้วยครับ แอดไปหน้า Favorite พอปิด iOS Simulator แล้วเปิดใหม อยากไห้มีข้อมูล หน้า Favorite เหมือนตอนแอดครับ!!
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 04
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่