【发布时间】:2017-09-30 04:33:27
【问题描述】:
我想从我的第一个控制器传递一些变量:
float user_distance;
UIImage *user;
float user_battery;
NSString *user_name;
到第二个控制器。 两者之间的联系是通过函数实现的:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
以这种方式:
UserViewController *secondViewController = [[UserViewController alloc] initWithNibName:@"UserViewController" bundle:nil];
[self.navigationController pushViewController:secondViewController animated:YES];
如何从这个函数中恢复值?
提前致谢!
【问题讨论】:
-
您管理数据源,因此从
indexPath,您可以检索(数组?)数据源的值。您现在可以将这些值设置为secondViewController。 -
如何从 indexpath 中检索第一个变量的值?
-
这取决于你如何编码
tableView:cellForRowAtIndexPath: -
secondViewController.device = [self.arrayOfDevices objectAtIndex:indexPath.row]然后呢?UserViewController具有device类SEC_Device的属性。
标签: ios objective-c uitableview xib