2013-04-10 66 views

回答

0

您應該將靜態單元格綁定到您的UITableViewController中的網點,並將配置文件同步方法設置爲- viewWillAppear方法。

當用戶更改國家/地區列表中的國家/地區時,配置文件會更新。之後,當用戶移回帶有靜態內容的UITableViewController實例時,配置文件數據將自動更新。

0

您可以在CityTableView中定義一個委託,然後在此委託中定義一個方法。

您應該在CountryTableView中實現此方法。

然後你可能會得到你想要的。

我只給你一個想法。你應該自己找到細節。

0

MasterViewController.h

#import "DetailViewController.h" 

@interface MasterViewController : UITableViewController <DetailProtocol> // Note this. 

@property (strong, nonatomic) DetailViewController *detailViewController; 
@property (strong, nonatomic, readwrite) NSString *selectedCountry; 

@end 

MasterViewController.m

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (!self.detailViewController) { 
     self.detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil]; 
    } 
    self.detailViewController.delegate = self; // THIS IS IMPORTANT... 
    [self.navigationController pushViewController:self.detailViewController animated:YES]; 
} 

// Note this -- It's a delegate method implementation 
- (void)setCountry:(NSString *)country 
{ 
    self.selectedCountry = country; 
} 

DetailViewController.h

@protocol DetailProtocol <NSObject> 
-(void)setCountry:(NSString *)country; 
@end 

@interface DetailViewController : UIViewController 

@property (strong, nonatomic) IBOutlet UITableView *tableView; 
@property (unsafe_unretained) id <DetailProtocol> delegate; // Note this 

@end 

DetailViewController.m

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; 
    [self.delegate setCountry:[countries objectAtIndex:indexPath.row]]; // Note this 
    [self.navigationController popViewControllerAnimated:YES]; 
} 
相關問題