我有一个数组。这个数组从 TableView 中的 Web 服务加载。
tableview 中有所有 BranchId。我想在选择行时显示所选 branchId 的字段。
例如在表格视图中选择“1234”
打开新的视图控制器(DetailViewController):
分行编号:1234
分行名称:ABCDEFGH
我在 Web 服务中有 Branchname
表视图代码:http : //pastie.org/8052416
如何在新视图控制器上显示选定 ID 的详细信息?谢谢
我有一个数组。这个数组从 TableView 中的 Web 服务加载。
tableview 中有所有 BranchId。我想在选择行时显示所选 branchId 的字段。
例如在表格视图中选择“1234”
打开新的视图控制器(DetailViewController):
分行编号:1234
分行名称:ABCDEFGH
我在 Web 服务中有 Branchname
表视图代码:http : //pastie.org/8052416
如何在新视图控制器上显示选定 ID 的详细信息?谢谢
有不同的方法,这里是一个:从你的第一个 viewController:
NSDictionary* dict = [NSDictionary dictionaryWithObject:
[NSNumber numberWithInt:theIdYouWantToSend]
forKey:@"index"];
[[NSNotificationCenter defaultCenter] postNotificationName: @"getID" object: dict];
现在从新的视图控制器(detailViewController),在 viewDiDLoad 方法中:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getID:) name:@"getID" object:nil];
并创建方法:
-(void)getID:(NSNotification*)notification{
NSDictionary* dict = (NSDictionary*) notification.object;
}
您可以轻松地从字典中获取 ID
myId = [dict objectForKey:@"index"];
您应该通过以下方式修改 didSelectRow 方法:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailViewController *second=[[DetailViewController alloc]
initWithNibName:@"DetailViewController" bundle:nil] ;
second.branchId = [myArray objectAtIndex:indexPath.row];
[self presentModalViewController:second animated:YES];
}