欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

iOS開(kāi)發(fā)Notification傳值


網(wǎng)站建設(shè)哪家好,找成都創(chuàng)新互聯(lián)公司!專(zhuān)注于網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)站建設(shè)、微信開(kāi)發(fā)、重慶小程序開(kāi)發(fā)公司、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。為回饋新老客戶(hù)創(chuàng)新互聯(lián)還提供了徽縣免費(fèi)建站歡迎大家使用!

通知傳值


第一個(gè)UIViewcontroller.h

#import <UIKit/UIKit.h>

@interface UseNotifi_VCOne :UIViewController

@end

UIViewcontroller.m

- (void)viewDidLoad
{
   [super viewDidLoad];
   // Do any additional setup after loading the view from its nib.
   
   
   //監(jiān)聽(tīng)某個(gè)通知
   //這里需要注意到 : 通知只能是 對(duì)象才可用,且該對(duì)象必須存在于內(nèi)存中
   /*
    [NSNotificationCenter defaultCenter] 獲取通知的管理
    addObserver: 設(shè)置通知的監(jiān)聽(tīng)者
    */
   //NOTIFICATION_CHANHECONTENT 在 QFUseNotifi_VCTwo中
   [[NSNotificationCenter defaultCenter]  addObserver:self selector:@selector(contentChange:) name:NOTIFICATION_CHANGECONTENT object:nil];
   
}

-(void)dealloc
{    //       通知
   //         |
  //         \ /
 //    對(duì)象-->監(jiān)聽(tīng)<--通知
//  將當(dāng)前對(duì)象監(jiān)聽(tīng)的所有通知移除
   [[NSNotificationCenter defaultCenter]  removeObserver:self];
   
   //移除指定name關(guān)聯(lián)的通知
   [[NSNotificationCenter defaultCenter] removeObserver:self name:NOTIFICATION_CHANGECONTENT object:nil];
}
//收到通知后,觸發(fā)的方法,然后做相應(yīng)的處理
-(void)contentChange:(NSNotification *)notification
{                                                                  
                                                         //userInfo : 通知里捆綁的數(shù)據(jù)
   self.detailLab.text = [NSString stringWithFormat:@"“%@” 發(fā)來(lái)賀電",[notification.userInfo objectForKey:@"ChangeContent"]];
}

#pragma mark - 用戶(hù)交互(push第二個(gè)控制器UseNotifi_VCTwo)

- (IBAction)gotoPostNotifiVC:(id)sender {
   
   UseNotifi_VCTwo *vc = [[UseNotifi_VCTwo alloc] init];
   
   [self.navigationController pushViewController:vc animated:YES];
   
}


第二個(gè)UIviewController( UseNotifi_VCTwo.h)

#import <UIKit/UIKit.h>

/*
通知的發(fā)送者     xxxxxxxxxxxxxxxxxxxxxxxxxx
*/

//定義 通知的 標(biāo)識(shí),根據(jù)需要選擇將 #define 定義在具體的文件中,如.pch、.h等
#define  NOTIFICATION_CHANGECONTENT @"Notification_ChangeContent"http://通知的標(biāo)識(shí)

@interface UseNotifi_VCTwo : UIViewController

@end

第二個(gè)UIviewController( UseNotifi_VCTwo.m)

@interface UseNotifi_VCTwo ()

@property (weak, nonatomic) IBOutlet UITextField *nameTF;

@end

@implementation UseNotifi_VCTwo

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
   self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
   if (self) {
       // Custom initialization
       self.title = @"發(fā)送通知的控制器";
   }
   return self;
}

- (void)viewDidLoad
{
   [super viewDidLoad];

}

- (void)didReceiveMemoryWarning
{
   [super didReceiveMemoryWarning];
}

#pragma mark - 用戶(hù)交互(post回去)
- (IBAction)postNotificationAction:(id)sender {
   
   NSString *uname = self.nameTF.text;
   NSDictionary *ChangeContent = [NSDictionary dictionaryWithObject:uname forKey:@"ChangeContent"];
   
   //發(fā)送一個(gè)通知
   /*
    [NSNotificationCenter defaultCenter]  獲取全局通知對(duì)象
    postNotificationName: 通知的標(biāo)識(shí),必須設(shè)置
    object: 用于通知的過(guò)濾,將通知捆綁一個(gè)obj,一般設(shè)為nil
    userInfo: 發(fā)送通知所捆綁的用戶(hù)數(shù)據(jù)
    */
    [[NSNotificationCenter defaultCenter]
    postNotificationName:NOTIFICATION_CHANGECONTENT
                  object:nil
                userInfo:ChangeContent];
   
   [self.navigationController popViewControllerAnimated:YES];
}

@end

當(dāng)前題目:iOS開(kāi)發(fā)Notification傳值
標(biāo)題路徑:http://chinadenli.net/article6/ppgoog.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序品牌網(wǎng)站建設(shè)、移動(dòng)網(wǎng)站建設(shè)、云服務(wù)器、自適應(yīng)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站建設(shè)