sách gpt4 ai đã đi

iphone - NSNotificationCenter 不对消息起作用

In lại 作者:行者123 更新时间:2023-11-29 11:18:54 27 4
mua khóa gpt4 Nike

在我的一个类(class)中,我发布了一条通知:

[[NSNotificationCenter defaultCenter] postNotificationName:@"ALERTNOTI" object:self userInfo:nil];

在我的应用委托(delegate)中,我会听:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMethod) name:@"ALERTNOTI" object:nil];

Tôi sử dụng NSLog 来跟踪我何时发送以及何时调用方法 myMethod.

尽管我发送了通知,但该方法没有被调用。

Về NSNotification 有什么我需要知道的吗?脾气暴躁吗?

1 Câu trả lời

 do this changes

[[NSNotificationCenter defaultCenter] postNotificationName:@"ALERTNOTI" object:nil];

if you want to pass some object through the notification. then do this
ex: you want to pass an NSDictionary *dict

[[NSNotificationCenter defaultCenter] postNotificationName:@"ALERTNOTI" object:nil userInfo:dict];

你想通过通知调用的方法应该是这样的。

  -(void)method:(NSNotification *) notif
{
// your code here.

//if you want to access your dict
NSDictionary *myDict=[notif userInfo];



}

关于iphone - NSNotificationCenter 不对消息起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8166118/

27 4 0
行者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