Three-tier MVC Architecture

Source: Internet
Author: User

Three-tier MVC Architecture
New ViewController class inherits UIViewController

AppDelegate. m

# Import "ViewController. h "# pragma mark-Override # pragma mark dealloc-(void) dealloc {[_ window release]; [super dealloc];} // set window self. window = [[[UIWindow alloc] init] autorelease]; self. window. frame = [UIScreen mainScreen]. bounds; self. window. backgroundColor = [UIColor whiteColor]; [self. window makeKeyAndVisible]; // set the Root View Controller ViewController * RootVC = [[ViewController alloc] init]; self. window. rootViewController = RootVC; [RootVC release];
New RootView class inherits UIView

Write in RootView. m

# Pragma mark-rewriting # pragma mark dealloc-(void) dealloc {[_ userName release]; [_ userPWD release]; [_ loginButton release]; [_ registerButton release]; [super dealloc];}-(instancetype) initWithFrame :( CGRect) frame {self = [super initWithFrame: frame]; if (self) {[self addAllViews];} return self ;} -(void) addAllViews {self. backgroundColor = [UIColor whiteColor]; self. userName = [[LTView alloc] initWithFrame: CGRectMake (30, 50,260, 40) text: @ "userName" placeHolder: @ "enter userName" isSecure: NO]; [self addSubview: _ userName]; [_ userName release]; self. userPWD = [[LTView alloc] initWithFrame: CGRectMake (30,100,260, 40) text: @ "password" placeHolder: @ "enter the password" isSecure: YES]; [self addSubview: _ userPWD]; [_ userPWD release]; self. loginButton = [UIButton buttonWithType: UIButtonTypeSystem]; self. loginButton. frame = CGRectMake (40,160, 80, 40); [self. loginButton setTitle: @ "login" forState: UIControlStateNormal]; [self addSubview: self. loginButton]; self. registerButton = [UIButton buttonWithType: UIButtonTypeSystem]; self. registerButton. frame = CGRectMake (150,160, 80, 40); [self. registerButton setTitle: @ "register" forState: UIControlStateNormal]; [self addSubview: self. registerButton];}
Write in ViewController. m
# Pragma mark-rewriting # pragma mark dealloc-(void) dealloc {[_ rootView release]; [_ userName release]; [_ userPWD release]; [super dealloc];} // write only these three sentences-(void) loadView {self. rootView = [[RootView alloc] initWithFrame: [UIScreen mainScreen]. bounds]; self. view = self. rootView; [_ rootView release];}
Simulated memory warning
# Pragma mark-simulated memory warning-(void) didReceiveMemoryWarning {[super didreceivemorywarning]; // if the Controller executes the viewDidLoad method (loading process ), if the view controlled by the controller is not displayed on the window, release the view controlled by the controller if ([self isViewLoaded] & self. view. window = nil) {self. view = nil;} NSLog (@ "receive memory warning"); // Dispose of any resources that can be recreated .}
Page Jump
-(Void) viewDidLoad {[super viewDidLoad]; [self. rootView. loginButton addTarget: self action: @ selector (loginButtonDidClicked :) forControlEvents: UIControlEventTouchUpInside]; [self. rootView. registerButton addTarget: self action: @ selector (operator :) forControlEvents: UIControlEventTouchUpInside];} # pragma mark-loginButton Click Event-(void) loginButtonDidClicked :( UIButton *) sender {NSLog (@ "click to log on");}-(void) registerButtonDidClicked :( UIButton *) sender {RegisterViewController * registerVC = [[RegisterViewController alloc] init]; // simulate the launch page and go to the next level: [self presentViewController: registerVC animated: YES completion: nil];}-(void) viewDidLoad {[super viewDidLoad]; [self. rooView. backButton addTarget: self action: @ selector (backButtonDidClicked :) forControlEvents: Success];} // page Jump-(void) backButtonDidClicked :( UIButton *) sender {[self resume: YES completion: nil];}

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.