我的函数问题是我不确定如何传递我选择的数据并返回到之前的 View Controller 。链接是整个段落,http://pastebin.com/AtMjLD66 (抱歉,我没有 10 个声望,对给您带来的不便深表歉意)干杯。
最佳答案
我会推荐代表这样做,但如果你不想这样做,NSNotification 会在这里节省你的时间。
添加此内容在advanceVC.m中,可能在viewDidLoad中
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(someThingSelectedInDetail:) name:@"someThingSelectedInDetail" object:nil];
- (void)someThingSelectedInDetail:(NSNotification*)notificationObject
{
NSString *chefName = notificationObject.object;
NSLog(@"Chef Name from notification: %@",chefName);
}
并在 advanceDetailVC.m 的 didSelect 中执行此操作。
UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
[[NSNotificationCenter defaultCenter ]postNotificationName:@"someThingSelectedInDetail" object: cell.textLabel.text];
这里不是传递标签的文本,而是传递索引路径,因此直接从数组中获取它并将其传递到通知中,如下所示
[[NSNotificationCenter defaultCenter ]postNotificationName:@"someThingSelectedInDetail" object: [detailArray objectAtIndex:indexPath.row]];
关于ios - 如何将选定的数据传递回之前的 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19395343/