首页 > 移动平台 > 详细

ios通知使用 书上案例 简单易懂

时间:2014-06-27 20:38:23      阅读:332      评论:0      收藏:0      [点我收藏+]


/* The notification name */
const NSString *ResultOfAppendingTwoStringsNotification =
@"ResultOfAppendingTwoStringsNotification"; /* Keys inside the dictionary that our notification sends */
const NSString
*ResultOfAppendingTwoStringsFirstStringInfoKey = @"firstString";
const NSString
*ResultOfAppendingTwoStringsSecondStringInfoKey = @"secondString";
const NSString
*ResultOfAppendingTwoStringsResultStringInfoKey = @"resultString";

//发送通知方法
- (void) broadcastNotification{
    
    NSString *firstName = @"Anthony";
    NSString *lastName = @"Robbins";
    NSString *fullName = [firstName stringByAppendingString:lastName];
    
    NSArray *objects = [[NSArray  alloc] initWithObjects:
                        firstName,
                        lastName,
                        fullName,
                        nil];
    NSArray *keys = [[NSArray alloc] initWithObjects: ResultOfAppendingTwoStringsFirstStringInfoKey, ResultOfAppendingTwoStringsSecondStringInfoKey, ResultOfAppendingTwoStringsResultStringInfoKey,
                     nil];
    NSDictionary *userInfo = [[NSDictionary alloc] initWithObjects:objects forKeys:keys];
    NSNotification *notificationObject =
    [NSNotification notificationWithName:(NSString *)ResultOfAppendingTwoStringsNotification object:self
                                userInfo:userInfo];
    [[NSNotificationCenter defaultCenter] postNotification:notificationObject];
    
}

//监听通知调用方法
- (void) appendingIsFinished:(NSNotification *)paramNotification
{
    
    NSLog(@"Notification is received.");
    NSLog(@"Notification Object = %@",[paramNotification object]);
    NSLog(@"Notification User-Info Dict = %@", [paramNotification userInfo]);
}


- (void)viewDidLoad
{
    //监听通知
    [[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(appendingIsFinished:)
     name:(NSString *)ResultOfAppendingTwoStringsNotification object:self];
    
    
    //发送通知
    [self broadcastNotification];
    
}

ios通知使用 书上案例 简单易懂,布布扣,bubuko.com

ios通知使用 书上案例 简单易懂

原文:http://www.cnblogs.com/codeforcode/p/3809622.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!