Development mode for iOS agent (delegate)

Source: Internet
Author: User
Tags getcolor uikit

1. Proxy mode in IOS development use a lot of such as Uitableview,uicollectioin Proxy way, with too much, the surface of the consciousness is, entrust others to do things, help Viewcontroller to solve a series of problems, directly on the code:

In ChilderViewController.h:

#import <UIKit/UIKit.h>

@protocol childerviewcontrollerdlegate <nsobject>

 - (void) GetColor: (uicolor *) color;

@end

@interface childerviewcontroller: uiviewcontroller

@property (nonatomic,weak)ID <childerviewcontrollerdlegate >delegate;

@end

In CHILDERVIEWCONTROLLER.M:

#import "ChilderViewController.h"

@interface childerviewcontroller ()

@end

@implementation Childerviewcontroller

-(void) viewdidload {

[Super viewdidload];

self. View. BackgroundColor = [uicolor whitecolor];

UIButton *button = [[UIButton alloc] initwithframe:cgrectmake(0, 100, 200, 50 )];

[Button addTarget:self action:@selector(show) forcontrolevents: UIControlEventTouchUpInside];

//Button.backgroundcolor = [Uicolor redcolor];

[Button settitlecolor: [uicolor blackcolor] forstate:uicontrolstatenormal ];

[Button settitle:@ " return to the calling agent " forstate:uicontrolstatenormal];

[self. View addsubview: button];

}

-(void) show {

[self. Delegate getColor: [uicolor redcolor]];

[self. Navigationcontroller poptorootviewcontrolleranimated:YES];

}

-(void) didreceivememorywarning {

[Super didreceivememorywarning];

//Dispose of any resources the can be recreated

}

In a mainvccongtroller push past Childerviewcontrller, click the button in Childerviewcontroller to change the background color of the root view:

Mainviewcontroller.m

#import "MainViewController.h"

#import "ChilderViewController.h"

@interface Mainviewcontroller () <childerviewcontrollerdlegate>

@end

@implementation Mainviewcontroller

-(void) viewdidload {

[Super viewdidload];

additional setup after loading the view from its nib.

}

-(void) didreceivememorywarning {

[Super didreceivememorywarning];

//Dispose of any resources, can be recreated.

}

-(void) GetColor: (uicolor *) color{

self. View. BackgroundColor = color;

NSLog(@ "Change color ...");

}

-(ibaction) OnClick: (ID) Sender {

childerviewcontroller *childervc = [[childerviewcontroller alloc]init];

CHILDERVC. delegate = self;

[self. Navigationcontroller pushviewcontroller: childervc animated:YES];

}

Development mode for iOS agent (delegate)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.