028 using a list to achieve jumps between different interfaces

Source: Internet
Author: User
Tags uikit

The effect is as follows:

ViewController.h

1 #import <UIKit/UIKit.h>23@interface  viewcontroller: Uiviewcontroller4@end

Viewcontroller.m

1 #import "ViewController.h"2 3 @interfaceViewcontroller ()4 @end5 6 @implementationViewcontroller7 8- (ID) init {9     if(self =[Super Init]) {Ten         //self.title = @ "Hello"; OneSelf.navigationItem.title =@"Hello"; A     } -     returnSelf ; - } the  -- (void) Viewdidload { - [Super Viewdidload]; -      +uilabel* lblmessage =[[UILabel alloc] initWithFrame:self.view.bounds]; -Lblmessage.text =@"Hello, world!."; +Lblmessage.textalignment =Nstextalignmentcenter; ALblmessage.textcolor =[Uicolor Blackcolor]; atLblmessage.backgroundcolor =[Uicolor Whitecolor]; -Lblmessage.autoresizingmask = Uiviewautoresizingflexiblewidth |Uiviewautoresizingflexibleheight; - [Self.view addsubview:lblmessage]; - } -  -- (void) didreceivememorywarning { in [Super didreceivememorywarning]; -     //Dispose of any resources the can be recreated. to } +  - @end

ViewController2.h

1 #import <UIKit/UIKit.h>23@interface  ViewController2: Uiviewcontroller4@end

Viewcontroller2.m

1 #import "ViewController2.h"2 3 @interfaceViewController2 ()4 @end5 6 @implementationViewController27 8- (ID) init {9     if(self =[Super Init]) {Ten         //self.title = @ "Hello"; OneSelf.navigationItem.title =@"Hello"; A     } -     returnSelf ; - } the  -- (void) Viewdidload { - [Super Viewdidload]; -      +uilabel* lblmessage =[[UILabel alloc] initWithFrame:self.view.bounds]; -Lblmessage.text =@"Hello, world! "; +Lblmessage.textalignment =Nstextalignmentcenter; ALblmessage.textcolor =[Uicolor Whitecolor]; atLblmessage.backgroundcolor =[Uicolor Blackcolor]; -Lblmessage.autoresizingmask = Uiviewautoresizingflexiblewidth |Uiviewautoresizingflexibleheight; - [Self.view addsubview:lblmessage]; - } -  -- (void) didreceivememorywarning { in [Super didreceivememorywarning]; -     //Dispose of any resources the can be recreated. to } +  - @end

TopMenuController.h

1 #import <UIKit/UIKit.h>23@interface  topmenucontroller: Uitableviewcontroller4 @property (nonatomic, strong) nsmutablearray* Marritem; 5 6 @end

Topmenucontroller.m

1 #import "TopMenuController.h"2 3 @implementationTopmenucontroller4- (ID) init {5   if(self =[Super Initwithstyle:uitableviewstyleplain]) {6Self.title =@"Main Menu";7     //initializing an array for display8_marritem = [[Nsmutablearray alloc] Initwithobjects:@"Viewcontroller",@"ViewController2", nil];9   }Ten   returnSelf ; One } A  - #pragmaMark-----Uitableviewdatasource Methods----- --(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section { the   return[_marritem Count]; - } -  --(uitableviewcell*) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath { +UITableViewCell *cell =[[UITableViewCell alloc] initwithframe:cgrectzero]; -Cell.textLabel.text =[_marritem ObjectAtIndex:indexPath.row]; +   returncell; A } at  - #pragmaMark-----uitableviewdelegate Methods----- -- (void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) Indexpath { -Classclass=nsclassfromstring ([_marritem objectAtIndex:indexPath.row]); -   IDViewcontroller = [[classalloc] init]; -   if(viewcontroller) { in [Self.navigationcontroller Pushviewcontroller:viewcontroller animated:yes]; -   }  to } +  - @end

AppDelegate.h

1 #import <UIKit/UIKit.h>23@interface Appdelegate:uiresponder < Uiapplicationdelegate>4 @property (Strong, Nonatomic) UIWindow *window; 5 @property (Strong, Nonatomic) Uinavigationcontroller *Navigationcontroller; 6 7 @end

Appdelegate.m

1 #import "AppDelegate.h"2 #import "TopMenuController.h"3 4 @interfaceappdelegate ()5 @end6 7 @implementationappdelegate8 9-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {TenTopmenucontroller *topmenucontroller =[[Topmenucontroller alloc] init]; One_navigationcontroller =[[Uinavigationcontroller alloc] initwithrootviewcontroller:topmenucontroller]; A      -_window =[[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]; -_window.rootviewcontroller =Topmenucontroller; the [_window Addsubview:_navigationcontroller.view]; - [_window makekeyandvisible]; -     returnYES; - } +  -- (void) Applicationwillresignactive: (UIApplication *) Application { + } A  at- (void) Applicationdidenterbackground: (UIApplication *) Application { - } -  -- (void) Applicationwillenterforeground: (UIApplication *) Application { - } -  in- (void) Applicationdidbecomeactive: (UIApplication *) Application { - } to  +- (void) Applicationwillterminate: (UIApplication *) Application { - } the  * @end

028 using a list to achieve jumps between different interfaces

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.