Usm*_*Ali 0 uitableview uiviewcontroller viewdidload ios
我有一个tableViewController,我从中导航到UIViewController.为了保存indexPath.row的值,我使用了一个整数,并基于该整数操作在UIViewController中执行.问题是,当我按下后退按钮并选择另一个表索引时,它会导航到UIViewContoller,但执行的操作是第一个.第二次不调用ViewDidLoad.这是我的代码.
TableView代码:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (!self.iaRecipieViewController) {
self.iaRecipieViewController = [[[iRecipieViewController alloc] initWithNibName:@"iRecipieViewController" bundle:nil] autorelease];
}
if (indexPath.row == 0) {
self.iaRecipieViewController.myLableArray =labelSoupArray ;
}
if (indexPath.row == 1) {
self.iaRecipieViewController.myLableArray =labelSoupArray ;
}
if (indexPath.row == 2) {
self.iaRecipieViewController.myLableArray =labelSoupArray ;
}
// custom string is an NSinteger
self.iaRecipieViewController.customString = indexPath.row;
NSLog(@" int %i",self.iaRecipieViewController.customString);
NSLog(@"index path %i ", indexPath.row) ;
[self.navigationController pushViewController:iaRecipieViewController animated:YES];
[detailTable reloadData];
}
Run Code Online (Sandbox Code Playgroud)
UIViewController代码.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
myLabel.text = [self.myLableArray objectAtIndex:customString];
}
Run Code Online (Sandbox Code Playgroud)
使用 viewWillAppear:(BOOL)animated
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
myLabel.text = [self.myLableArray objectAtIndex:customString];
}
Run Code Online (Sandbox Code Playgroud)
只有在加载视图时才会调用viewDidLoad; 推送一个新的ViewController然后删除它不会强制重新加载视图.viewWillAppear在呈现视图之前被调用,因此您有机会在它成为主视图时执行操作.
| 归档时间: |
|
| 查看次数: |
4718 次 |
| 最近记录: |