我有一个数组,这个数组是从TableView的Web服务加载的。
tableview中有所有的BranchId。我想在选定的行时显示选定的branchId的字段。
例如,在表格视图中选择“ 1234”
打开新的视图控制器(DetailViewController):
分支ID:1234
分支机构名称:ABCDEFGH
我在Web服务中有Branchname
TableviewCodes: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"];