sách gpt4 ai đã đi

ios - NSNotificationCenter 帮助?

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

我有一个读取条形码的类,当我读取条形码时,我会向 NSNotificationCenter 发送通知,如下所示。

-(void)barcodeData:(NSString *)barcode type:(int)type {

barcodeValue = barcode;

[[NSNotificationCenter defaultCenter] postNotificationName:@"BarcodeRead" object:self];

}

然后在一些 View Controller 中我添加了观察者以获取条形码值,就像 .

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


-(void) BarcodeRead
{
//
}

问题是当一个通知被发送到通知中心时,在我添加观察者的所有 View 中他们得到通知并调用方法 BarcodeRead,但我想如果应用程序在 View Controller “A”中只是一个获取通知而不是全部。

谢谢你的帮助

1 Câu trả lời

我通常将注册/注销代码放入 viewWillAppear/viewWillDisappear 方法中,以确保通知仅在 Controller 处于事件状态时显示。

关于ios - NSNotificationCenter 帮助?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8027017/

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