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];
        
    }

  • 相关阅读:
    【java】JDBC连接MySQL
    【java】网络socket编程简单示例
    【java】对象序列化Serializable、transient
    【java】扫描流Scanner接收输入示例
    【java】缓冲字符字节输入输出流:java.io.BufferedReader、java.io.BufferedWriter、java.io.BufferedInputStream、java.io.BufferedOutputStream
    【java】System成员输入输出功能out、in、err
    33-Java中的String,StringBuilder,StringBuffer三者的区别
    5-Error:failed to find Build Tools revision 28.0.0 rc1解决方案
    46-wxpython 4 使用 grid 展示表格
    45-暴力密码字典
  • 原文地址:https://www.cnblogs.com/lisa090818/p/3311913.html
Copyright © 2011-2022 走看看