Iphone 当将数据从选定的tableview行传递到viewcontroller时,我对得到的结果感到困惑
为什么在DetailViewController中,NSLogs在viewDidLoad中分别返回标签和(null),而在iAction中,它们从所选行返回预期值?如何在viewDidLoad中获得正确的值 TableViewControllerIphone 当将数据从选定的tableview行传递到viewcontroller时,我对得到的结果感到困惑,iphone,objective-c,ios,uitableview,Iphone,Objective C,Ios,Uitableview,为什么在DetailViewController中,NSLogs在viewDidLoad中分别返回标签和(null),而在iAction中,它们从所选行返回预期值?如何在viewDidLoad中获得正确的值 TableViewController - (void)tableView:(UITableView *) tableView didSelectRowAtIndexPath:(NSIndexPath *__strong)indexPath { DetailViewControlle
- (void)tableView:(UITableView *) tableView didSelectRowAtIndexPath:(NSIndexPath *__strong)indexPath {
DetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"Detail"];
[self.navigationController pushViewController:detail animated:YES];
NSUInteger row = [indexPath row];
detail.selected1.text = [array1 objectAtIndex:row];
detail.selected2 = [array2 objectAtIndex:row]; }
-(void) viewDidLoad
{
NSLog(@"Log: %@", selected1.text);
NSLog(@"Log: %@", selected2);
}
- (IBAction) test:(id)sender
{
NSLog(@"Log: %@", selected1.text);
NSLog(@"Log: %@", selected2);
}
详细视图控制器
- (void)tableView:(UITableView *) tableView didSelectRowAtIndexPath:(NSIndexPath *__strong)indexPath {
DetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"Detail"];
[self.navigationController pushViewController:detail animated:YES];
NSUInteger row = [indexPath row];
detail.selected1.text = [array1 objectAtIndex:row];
detail.selected2 = [array2 objectAtIndex:row]; }
-(void) viewDidLoad
{
NSLog(@"Log: %@", selected1.text);
NSLog(@"Log: %@", selected2);
}
- (IBAction) test:(id)sender
{
NSLog(@"Log: %@", selected1.text);
NSLog(@"Log: %@", selected2);
}
viewDidLoad在加载视图控制器(即InstanceEviewControllerWithiIdentifier:)后被调用。因此,在设置标签时,viewDidLoad已经运行并返回。尝试将日志语句放在ViewDidDisplay中