通知应用

NSNumber *theTag = [NSNumber numberWithInt:btn.tag];
NSDictionary *tagInfo = [NSDictionary dictionaryWithObject:theTag forKey:@"theTag"];
// 设置通知
[[NSNotificationCenter defaultCenter] postNotificationName:@"setView" object:nil userInfo:tagInfo];

// 接收通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(choosenBtn:) name:@"setView" object:nil];

/**
 *  通知触发方法
 */
- (void)choosenBtn: (NSNotification*) aNotification
{
    MLTabBarButton *btn = [[MLTabBarButton alloc] init];
    NSDictionary *tagInfo = aNotification.userInfo;
    NSString *a = [tagInfo objectForKey:@"theTag"];
    // 字符串转integer
    btn.tag = [a integerValue];
    [self btnOnClick:btn];
    [self setSelectIndex:btn.tag];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"setView" object:nil];
}
    原文作者:Dean
    原文地址: https://segmentfault.com/a/1190000002228827
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞