Tôi đang cố gắng gửi một số dữ liệu bằng cách sử dụng NSNotification nhưng bị kẹt. Đây là mã của tôi:Cách chuyển userInfo trong NSNotification?
// Posting Notification
NSDictionary *orientationData;
if(iFromInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
orientationData = [NSDictionary dictionaryWithObject:@"Right"
forKey:@"Orientation"];
}
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter postNotificationName:@"Abhinav"
object:nil
userInfo:orientationData];
// Adding observer
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(orientationChanged)
name:@"Abhinav"
object:nil];
Bây giờ làm thế nào để lấy điển UserInfo này trong selector tôi orientationChanged?
Ok. Và làm thế nào để làm điều này? Có phải là: [[NSNotificationCenter defaultCenter] addObserver: tự chọn: @selector (orientationChanged: self) tên: @ "Abhinav" đối tượng: nil] ;? – Abhinav
[[NSNotificationCenter defaultCenter] addObserver: tự chọn: @selector (orientationChanged :) tên: @ "Abhinav" đối tượng: nil]; – JustSid
Bất kỳ lý do gì khiến một người có thể kết thúc bằng một từ điển nil? –