<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      View 與 Controller 之間的delegate(代理)傳值

      這個代理傳值是經(jīng)常使用的一種傳值方式,下面介紹一種View 和 Controller 之間的代理傳值方法。
      先建立一個View視圖
      如 LoginView 是繼承于一個UIView
      在LoginView.h里面聲明協(xié)議
      LoginView.h文件

         #import <UIKit/UIKit.h>
      

      @class LoginView;
      //1.聲明協(xié)議
      @protocol LoginViewDelegate
      @optional//可選的

      • (void)sureButtonTaped:(LoginView *)loginView info:(NSString *)info;
        @end
        @interface LoginView : UIView
        //2.聲明delegate屬性
        @property (nonatomic,assign) id delegate;
        @end

      在LoginView.m 有一個textField,一個button,點擊button,將textField里面的值傳入Controller里面。
      LoginView.m文件

      import "LoginView.h"

      @interface LoginView ()
      @property (nonatomic,strong)UITextField *textField;
      @property (nonatomic,strong) UIButton *button;

      @end

      @implementation LoginView

      • (instancetype)initWithFrame:(CGRect)frame
        {
        self = [super initWithFrame:frame];
        if (self) {
        self.backgroundColor = [UIColor yellowColor];

          [self setUp];
        

        }
        return self;
        }

      • (void)setUp{

        _textField = [[UITextField alloc] init];
        _textField.bounds = CGRectMake(0, 0, CGRectGetWidth(self.bounds) * 0.7, 40);
        _textField.center = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds) - 100);
        _textField.tintColor = [UIColor redColor];
        _textField.borderStyle = UITextBorderStyleLine;
        _textField.keyboardType = UIKeyboardTypeASCIICapable;
        _textField.placeholder = @"請輸入文字";
        _textField.clearButtonMode = UITextFieldViewModeWhileEditing;
        [self addSubview:_textField];

        _button = [UIButton buttonWithType:UIButtonTypeSystem];
        _button.frame = CGRectMake(120, 280, 80, 30);
        [_button setTitle:@"登陸" forState:UIControlStateNormal];
        [_button addTarget:self action:@selector(buttonTaped:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_button];

      }

      • (void)buttonTaped:(UIButton *)sender
        {
        //調(diào)用協(xié)議方法
        [_delegate sureButtonTaped:self info:_textField.text];

      }

      在這里我們用于接收的視圖就用一開始的ViewController,你也可以傳入你想要傳入的視圖

      ViewController.h文件

      import <UIKit/UIKit.h>

      @interface ViewController : UIViewController
      @end

      ViewController.m文件
      #import "ViewController.h"
      #import "LoginView.h"
      //引入?yún)f(xié)議

      @interface ViewController ()

      @end

      @implementation ViewController

      • (void)viewDidLoad {
        [super viewDidLoad];
        LoginView *login = [[LoginView alloc]initWithFrame:CGRectMake(20, 200, 375-40, 350)];
        //1.設(shè)置代理
        login.delegate = self;
        [self.view addSubview:login];

      }
      #pragma mark -- LoginViewDelegate
      //3.實現(xiàn)協(xié)議方法

      • (void)sureButtonTaped:(LoginView *)loginView info:(NSString *)info
        {

        NSLog(@"%@",info);

      }

      • (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
        }

      @end

      總結(jié):代理加方法的傳值是一種很好的傳值方式,我們可以將自己要傳入的值寫進方法里面,打包傳入,方便快捷。。

      posted @ 2016-10-10 15:52  懵懂少俠  閱讀(1099)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 久久亚洲精品11p| a级黑人大硬长爽猛出猛进| 国产精品一区二区黄色片| 亚洲 一区二区 在线| 国产精品白丝一区二区三区| 少妇办公室好紧好爽再浪一点| 国产精品久久久久久人妻精品动漫| 97欧美精品系列一区二区| 精品人妻大屁股白浆无码| 国产一二三五区不在卡| 日本久久99成人网站| 综合色一色综合久久网| 真实国产老熟女无套中出| 疯狂做受xxxx高潮视频免费| 久久96热在精品国产高清| 国内精品伊人久久久久av| 国产情侣草莓视频在线| 国产一区二区三区亚洲精品| a级国产乱理伦片在线观看al| 精品乱码一区二区三四五区| 五月天免费中文字幕av| 一级做a爰片在线播放| 欧美人成精品网站播放| 国产婷婷综合在线视频| 国产肥臀视频一区二区三区| 日日碰狠狠添天天爽五月婷| 最新国产AV最新国产在钱| 日韩精品无码免费专区午夜不卡| 国产不卡在线一区二区| 麻豆久久久9性大片| 亚洲欧美日韩在线不卡| 玩弄放荡人妻少妇系列| 国产精品爽爽v在线观看无码 | 蜜臀av久久国产午夜| 成人国产精品中文字幕| 亚洲精品二区在线播放| 久久精品亚洲中文字幕无码网站 | 国产精品综合av一区二区| 亚洲一区二区精品极品| 国产玩具酱一区二区三区| 国产精品久久久久无码网站|