欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

IOS四種反向傳值的方法-創(chuàng)新互聯(lián)

方法一:使用target-action設(shè)計(jì)模式

榮昌ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)公司的ssl證書銷售渠道,可以享受市場價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18982081108(備注:SSL證書合作)期待與您的合作!

    代碼如下:(由根視圖推出子視圖,再由子視圖推出根視圖,在推出根視圖時,子視圖傳一個color的屬性給根視圖,用來修改根視圖的背景顏色)

根視圖控制器代碼:

//.m文件
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor redColor];
    
    [self createButton];
}

- (void)createButton
{
    UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    btn.frame = CGRectMake(10, 30, 300, 40);
    [btn setTitle:@"進(jìn)入下一個視圖控制器" forState:UIControlStateNormal];
    btn.layer.cornerRadius = 5;
    
    btn.backgroundColor = [UIColor blackColor];
    
    [btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:btn];
}

- (void)btnClick
{
    Sub1ViewController * sub1 = [[Sub1ViewController alloc]init];
    
    sub1.view.backgroundColor = [UIColor blueColor];
    
    sub1.target = self;
    
    sub1.action = @selector(changeColor:);
    
    [self presentViewController:sub1 animated:YES completion:nil];
}

- (void)changeColor:(UIColor *)color
{
    self.view.backgroundColor = color;
}

子視圖代碼:

//.h文件

@interface Sub1ViewController : UIViewController
@property (assign,readwrite,nonatomic)id target;
@property (assign,readwrite,nonatomic)SEL action;
@end

//.m文件
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self createPopToRootViewBtn];
}

- (void)createPopToRootViewBtn
{
    UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    btn.frame = CGRectMake(10, 30, 300, 40);
    [btn setTitle:@"進(jìn)入根視圖控制器" forState:UIControlStateNormal];
    btn.layer.cornerRadius = 5;
    
    btn.backgroundColor = [UIColor blackColor];
    
    [btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:btn];
}

- (void)btnClick
{
    if ([_target respondsToSelector:_action])
    {
        [_target performSelector:_action withObject:[UIColor orangeColor]];
    }
    [self dismissViewControllerAnimated:YES completion:nil];
}

方法二:通知

//.m根視圖
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor redColor];
    
    [self createButton];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeColor:) name:@"ChangeColor" object:nil];
}

- (void)createButton
{
    UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    btn.frame = CGRectMake(10, 30, 300, 40);
    [btn setTitle:@"進(jìn)入下一個視圖控制器" forState:UIControlStateNormal];
    btn.layer.cornerRadius = 5;
    
    btn.backgroundColor = [UIColor blackColor];
    
    [btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:btn];
}

- (void)btnClick
{
    Sub1ViewController * sub1 = [[Sub1ViewController alloc]init];
    
    sub1.view.backgroundColor = [UIColor blueColor];
    
    [self presentViewController:sub1 animated:YES completion:nil];
}

- (void)changeColor:(NSNotification *)nofi
{
    self.view.backgroundColor = [nofi.userInfo objectForKey:@"color"];
}

子視圖代碼

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self createPopToRootViewBtn];
}

- (void)createPopToRootViewBtn
{
    UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    btn.frame = CGRectMake(10, 30, 300, 40);
    [btn setTitle:@"進(jìn)入根視圖控制器" forState:UIControlStateNormal];
    btn.layer.cornerRadius = 5;
    
    btn.backgroundColor = [UIColor blackColor];
    
    [[NSNotificationCenter defaultCenter]postNotificationName:@"ChangeColor" object:self userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor orangeColor],@"color", nil]];
    
    [btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:btn];
    
    
}

- (void)btnClick
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

方法三:代碼塊

    根視圖代碼:

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor redColor];
    
    [self createButton];
}

- (void)createButton
{
    UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    btn.frame = CGRectMake(10, 30, 300, 40);
    [btn setTitle:@"進(jìn)入下一個視圖控制器" forState:UIControlStateNormal];
    btn.layer.cornerRadius = 5;
    
    btn.backgroundColor = [UIColor blackColor];
    
    [btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:btn];
}

- (void)btnClick
{
    Sub1ViewController * sub1 = [[Sub1ViewController alloc]init];
    
    sub1.view.backgroundColor = [UIColor blueColor];
    
    sub1.MyBlock = ^(UIColor * color)
    {
        self.view.backgroundColor = color;
    };
    
    [self presentViewController:sub1 animated:YES completion:nil];
}

子視圖代碼

//.h文件
@interface Sub1ViewController : UIViewController
@property (copy,nonatomic,readwrite)void (^MyBlock)(UIColor * color);
@end
//.m文件
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self createPopToRootViewBtn];
}

- (void)createPopToRootViewBtn
{
    UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    btn.frame = CGRectMake(10, 30, 300, 40);
    [btn setTitle:@"進(jìn)入根視圖控制器" forState:UIControlStateNormal];
    btn.layer.cornerRadius = 5;
    
    btn.backgroundColor = [UIColor blackColor];
    
    [btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:btn];
    
    
}

- (void)btnClick
{
    _MyBlock([UIColor orangeColor]);
    [self dismissViewControllerAnimated:YES completion:nil];
}

方法四:代理-協(xié)議

根視圖代碼

//.h
#import <UIKit/UIKit.h>
#import "Sub1ViewController.h"
@interface ViewController : UIViewController<Sub1ViewControllerDelete>

@end
//.m
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor redColor];
    
    [self createButton];
}

- (void)createButton
{
    UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    btn.frame = CGRectMake(10, 30, 300, 40);
    [btn setTitle:@"進(jìn)入下一個視圖控制器" forState:UIControlStateNormal];
    btn.layer.cornerRadius = 5;
    
    btn.backgroundColor = [UIColor blackColor];
    
    [btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:btn];
}

- (void)btnClick
{
    Sub1ViewController * sub1 = [[Sub1ViewController alloc]init];
    
    sub1.view.backgroundColor = [UIColor blueColor];
    sub1.delegate = self;
    [self presentViewController:sub1 animated:YES completion:nil];
}

- (void)changeColor:(UIColor *)color
{
    self.view.backgroundColor = color;
}

子視圖控制器

//.h文件
#import <UIKit/UIKit.h>

@protocol Sub1ViewControllerDelete <NSObject>
- (void)changeColor:(UIColor *)color;
@end

@interface Sub1ViewController : UIViewController
@property (assign,nonatomic,readwrite)id <Sub1ViewControllerDelete>delegate;
@end
//.m文件
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self createPopToRootViewBtn];
}

- (void)createPopToRootViewBtn
{
    UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    btn.frame = CGRectMake(10, 30, 300, 40);
    [btn setTitle:@"進(jìn)入根視圖控制器" forState:UIControlStateNormal];
    btn.layer.cornerRadius = 5;
    
    btn.backgroundColor = [UIColor blackColor];
    
    [btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:btn];
    
    
}

- (void)btnClick
{
    [_delegate changeColor:[UIColor orangeColor]];
    
    [self dismissViewControllerAnimated:YES completion:nil];
}

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

本文題目:IOS四種反向傳值的方法-創(chuàng)新互聯(lián)
當(dāng)前鏈接:http://www.aaarwkj.com/article48/ddodep.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)頁設(shè)計(jì)公司、網(wǎng)站內(nèi)鏈、商城網(wǎng)站、響應(yīng)式網(wǎng)站ChatGPT、服務(wù)器托管

廣告

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

營銷型網(wǎng)站建設(shè)
日韩精品在线另类亚洲| 日韩欧美精品视频一区| 国产欧美日韩精品三级| 成年网站在线91九色| av男人的天堂一区二区| av中文字幕国产精品| 亚洲大尺码在线视频香蕉| 中文字幕一区二区精品区| 欧美日韩黄片免费在线观看| 高清欧美大片免费观看| 国产精品欧美一区二区视频| 日韩免费的黄色片网站| 日韩深夜成人在线视频| 99热在线免费观看精品| av黄色资源在线观看| 中文字幕中文字幕久久不卡| 中文字幕亚洲精品熟女少妇| 日韩人妻精品久久免费| 我的极品小姨在线观看| 浮力草草日韩欧美三级| 色一区欧美一区亚洲一区| 欧美三级视频一区二区三区| 亚洲男人堂色偷偷一区| 91人妻人澡人人爽| 黄色录像三级黄色录像三级黄色| 丰满人妻在线一区二区三区| 天天精品国产av九九久久久| 国产精品久久综合网| 五月婷婷丁香婷婷丁香| 一本综合九九国产二区| 久久免费观看性生活片| 成人性生交大片免费看中文| 日韩成人中文字幕电影| 中文字幕日韩一区二区| 久久综合久中文字幕青草| 福利一区福利二区视频| 亚洲午夜一区二区精品| 人妻乱人伦中文字幕在线| 美女黄色午夜福利网站| 人妖伪娘在线观看一区二区三区 | 97视频免费观看在线|