sách gpt4 ai đã đi

ios - NSNotificationCenter ,打印内存地址

In lại 作者:行者123 更新时间:2023-11-29 13:02:36 hai mươi bốn 4
mua khóa gpt4 Nike

我的应用程序中有一个 UITableview Controller ,一个 View Controller ,我正在尝试使用 NSNotificationCenter 将 NSDictionary 从 UITableview Controller 传递到我的 ViewController。所以,我在我的 UITableview Controller 上推送一个通知,然后我添加一个观察者,在我的 ViewController 上使用一个选择器。选择器被调用,但我有一个 NSLog 并获得内存结果,比如:

ViewController: 0x8a0bcc0

我试图传递 NSString 而不是 NSDictionary,但我再次得到内存结果,而不是字符串的值。

我的代码:

UITableView Controller

    NSString *string=@"This is a test string";
[[NSNotificationCenter defaultCenter] postNotificationName: @"Update" object: string];

View Controller

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(incomingNotification:) name:@"Update" object:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:@"Update" object:self];

这里是 incomingNotification 选择器方法:

-(void) incomingNotification : (NSNotification *)notification{
NSLog(@"Trying to print : %@",[notification object]);
}

所有通知都发生在 ViewDidLoad 方法中。谢谢!

làm mới

最后,我停止使用 NSNotificationCenter 并使用属性来传递数据,稍微改变了我的 TableViewController 的继承性。不知道为什么通知没有像预期的那样工作。谢谢大家,非常感谢您的建议和想法:)

1 Câu trả lời

[[NSNotificationCenter defaultCenter] postNotificationName:@"Update" object:self]

对象表示生成通知的对象。要发布参数,请使用另一种方法

[[NSNotificationCenter defaultCenter] postNotificationName:@"Update" object:self userInfo:string]

关于ios - NSNotificationCenter ,打印内存地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19435506/

hai mươi bốn 4 0
Bài viết được đề xuất: ios - iCloud 核心数据迁移
Bài viết được đề xuất: ios - UITableViewCell 中的 UIAttachmentBehavior
Bài viết được đề xuất: mySQL GROUP_CONCAT IN JOIN
Bài viết được đề xuất: mysql - SQL查询联合最佳实践
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com