zoukankan      html  css  js  c++  java
  • ios notification

    1,- (void)viewWillAppear:(BOOL)animated 中注册notification

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

    2,在接收notification地方实现方法体

    -(void)actionSheetSelect:(NSNotification *)notification{
        
        NSString* obj = (NSString*)[notification object];
        if ([obj isEqualToString:@"MobilePhone"]) {
            
            //load the view though psw
            
            GetPswThroughPhoneNumberViewController *pushView = [[GetPswThroughPhoneNumberViewController alloc] init];
            [self.navigationController pushViewController:pushView animated:YES];
            [pushView release];
        }
        else if([obj isEqualToString:@"Email"]){
            //load the view though email
            GetPswThroughEmailViewController *pushView = [[GetPswThroughEmailViewController alloc] init];
            [self.navigationController pushViewController:pushView animated:YES];
            [pushView release];
        }
        else{
            NSLog(@"erase");
        }
    }

    3,调用的地方发送请求

    - (void)buttonClicked:(id)sender {
        NSUInteger buttonIndex = ((UIView *)sender).tag - 100;
        
        [self dismissWithClickedButtonIndex:buttonIndex animated:YES];
        
        switch (buttonIndex) {
            case CMActionSheetButtonMobilePhoneIndex:
            {
                [[NSNotificationCenter defaultCenter] postNotificationName:@"actionSheetSelect" object:@"MobilePhone"];
                break;
            }
            case CMActionSheetButtonEmailIndex:
            {
                //load the view though email
                [[NSNotificationCenter defaultCenter] postNotificationName:@"actionSheetSelect" object:@"Email"];
                break;
            }
            case CMActionSheetButtonCancelIndex:
            {
                //cancel
                [[NSNotificationCenter defaultCenter] postNotificationName:@"actionSheetSelect" object:@"Cancel"];
                break;
            }
            default:
                break;
        }
        
    }

    4,在viewDidDisappear中注销掉notification

    - (void)viewDidDisappear:(BOOL)animated{
        
        [[NSNotificationCenter defaultCenter] removeObserver:self];
        
    }

  • 相关阅读:
    20190710-汉诺塔算法
    20190705-Python数据驱动之DDT
    20190621-N皇后
    还在为Excel合并单元格导致的各种问题烦恼吗?这里一起解决
    Excel基础:开始菜单之对齐方式,那些被遗忘的实用功能
    Excel中身份证号码如何分段显示,难倒小编,有什么好方法吗?
    制作这样的Excel注水图表,让老板另眼相看,坐等升职加薪
    Excel高手都会的Shift快捷键7个用法,让工作效率翻倍
    Excel答粉丝问:批量将单元格内容转为批注
    Excel基础:开始菜单之字体的华丽转身
  • 原文地址:https://www.cnblogs.com/lisa090818/p/3311913.html
Copyright © 2011-2022 走看看