【发布时间】:2017-07-25 11:16:37
【问题描述】:
我知道这个问题被问了很多次,我搜索了很多并尝试了很多解决方案但没有奏效。我制作了一个自定义表格视图,其中数据是从服务加载的。数据加载非常有限,当用户单击单元格时,我必须将数据的详细信息显示到新的视图控制器中。它应该传递携带数据的各个单元的数据。我尝试了 segue 技术将数据传递给新的 vc 但失败了,它显示我传递的值为 null 。我在新的 vc 中创建了一些标签,在其中我从表视图单元格中调用值。我的代码是,
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"ShowDetail"]) {
//Do something
ShowViewController *destViewController = segue.destinationViewController;
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
destViewController.tites = [_Title objectAtIndex:indexPath.row];
destViewController.prce = [_Price objectAtIndex:indexPath.row];
NSLog(@"PPPP is %@",destViewController.phon);
destViewController.ara = [_LandArea objectAtIndex:indexPath.row];
destViewController.phon = [_Phone objectAtIndex:indexPath.row];
destViewController.citi = [_City objectAtIndex:indexPath.row];
destViewController.loc = [_location objectAtIndex:indexPath.row];
destViewController.tye = [_type objectAtIndex:indexPath.row];
destViewController.Idss = [_Id objectAtIndex:indexPath.row];
destViewController.nam = [_name objectAtIndex:indexPath.row];
destViewController.emal = [_email objectAtIndex:indexPath.row];
destViewController.roomss = [_rooms objectAtIndex:indexPath.row];
destViewController.wash = [_washroom objectAtIndex:indexPath.row];
destViewController.flloors = [_floor objectAtIndex:indexPath.row];
destViewController.stat = [_status objectAtIndex:indexPath.row];
destViewController.descrp = [_descrip objectAtIndex:indexPath.row];
destViewController.countryy = [_country objectAtIndex:indexPath.row];
}
}
【问题讨论】:
-
这个
prepareForSegue方法被调用了吗?并且满足isEqualToString:@"ShowDetail"这个条件? -
yes 方法被调用,它移动到新的 vc 但我传递的值不会去,因为我有 NSLo 一些值,但它在它们前面显示 null。 @Mr.Bista
-
在分配给它之前注意你正在打印 phon 变量...
-
@HamzaImran 为什么要为每个属性使用一个数组,更好的方法是使用模型类来保留所有这些属性,也比传递一组属性更容易传递一个对象
标签: ios objective-c uitableview