【发布时间】:2009-07-01 07:26:55
【问题描述】:
我正在使用通知将数据从详细视图控制器传递到我的应用程序中的根视图控制器。在出现内存警告之前,这些方法都可以正常工作。
在任何内存警告后处理两次通知。
当用户在 DetailViewController 中选择一行时,我将数据传回 rootviewcontroller。 didSelectRowAtIndexPath 方法只被调用了一次,但是通知观察者被调用了两次!
我应该删除 didReceiveMemoryWarning 中的通知吗?还是代码有其他问题?
贴出相关代码
RootViewController 的 viewDidLoad
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(rowSelected:) name:@"SelectionNotification" object:nil];
DetailViewController 的 didSelectRowAtIndexPath
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSMutableDictionary *dictionary = [[[NSMutableDictionary alloc] init] autorelease];
[dictionary setObject:selectedRow forKey:@"row"];
[[NSNotificationCenter defaultCenter] postNotificationName:kSelectionNotificationName object:self userInfo:dictionary];
[[self navigationController] popToRootViewControllerAnimated:YES];
}
感谢您的帮助。
【问题讨论】:
标签: iphone notifications