码迷,mamicode.com
首页 > 移动开发 > 详细

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

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

标签:使用   string   os   cti   name   for   


/* 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通知使用 书上案例 简单易懂

标签:使用   string   os   cti   name   for   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!