问题描述
我的功能问题是我不确定如何传递我选择的数据,并返回到以前的视图控制器.链接是整个段落,http://pastebin.com/AtMjLD66(抱歉我没有 10声誉,很抱歉给您带来不便)加油.
My issue for my function is I am not sure how to pass the data which i selected, and back to the previous view controller. The link is to the whole paragraph,http://pastebin.com/AtMjLD66 (sorry I don't have 10 reputations, sorry about the inconvenience ) Cheer.
推荐答案
我会为此推荐委托,但如果您不想这样做,NSNotification 可以节省您的时间.
I would recommend delegates for this but if you don't want to do so, NSNotification would save your day here.
在 advanceVC.m 中添加它,可能在 viewDidLoad
Add this is in advanceVC.m probably in 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 中执行此操作.
And in didSelect of advanceDetailVC.m do this.
UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
[[NSNotificationCenter defaultCenter ]postNotificationName:@"someThingSelectedInDetail" object: cell.textLabel.text];
这里有索引路径,而不是传递标签的文本,因此直接从数组中获取它并像这样将其传递到通知中
Instead of passing a label's text you have the indexpath here so take it directly from the array and pass it in the notification like this
[[NSNotificationCenter defaultCenter ]postNotificationName:@"someThingSelectedInDetail" object: [detailArray objectAtIndex:indexPath.row]];
这篇关于如何将选定的数据传回上一个视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!