ios多窗体项目

http://www.cnblogs.com/dotey/archive/2011/06/09/2075954.html 第二个iPhone应用程序:“Say Hello”

 

http://edenhe.me/2011/04/28/uiwindow-uiview%E5%92%8Cuiviewcontroller/ UIWindow, UIView和UIViewController

 

http://www.cnblogs.com/ternastone/archive/2011/11/10/2244460.html IOS开发笔记(七)---对iOS多视图开发的补充(针对XCode4.2开发环境,

 

http://www.cocoachina.com/downloads/video/2010/1101/2272.html TabBarController与NavigationController嵌套的例子

 

 

google   tabbarcontroller navigationcontroller

NSMutableArray *controllers = [NSMutableArray array];

for (int i = 0; i < count; i++)
{

TableViewController * tabViewController = [[TableViewController alloc]initController:[item objectAtIndex:i]];//1
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:tabViewController];//2
[controllers addObject:nav];//3
}
UITabBarController *bar = [[UITabBarController alloc] init];
    bar.viewControllers = controllers;//4
    bar.customizableViewControllers = controllers;

UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];//1
    UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
    self.tabBarController = [[UITabBarController alloc] init];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];//2
    self.window.rootViewController = self.tabBarController;//3

1.通过navigationController来控制viewController

navigationController就像一个栈,可以放进很多viewController(pushViewController),显示的是栈顶上的viewController。

在appdelegate.h中添加:

@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
    UINavigationController * navigationcontroller;
}

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UINavigationController *navigationcontroller;

注意:UINavigationController一定要定义,如果直接在方法中这么写:

UINavigationController *navigationcontroller=[[UINavigationController alloc] initWithRootViewController:firstviewcontroller];//不要这样写

程序会崩溃。

在appdelegate.m中添加

 firstViewController * firstviewcontroller=[[firstViewController alloc] initWithNibName:@"firstViewController" bundle:nil];
    navigationcontroller=[[UINavigationController alloc] initWithRootViewController:firstviewcontroller];
    [self.window addSubview:navigationcontroller.view];

修改viewController.h

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title=@"firstViewController";
    
    UIBarButtonItem * weiboItem=[[UIBarButtonItem alloc] initWithTitle:@"newWeibo" style:UIBarButtonItemStyleDone target:self action:@selector(toNewWeibo)];
    
    self.navigationItem.leftBarButtonItem=weiboItem;

    button=[UIButton buttonWithType:1];
    
    button.frame=CGRectMake(100, 100, 100, 100);
    
    [button setTitle:@"toSecond" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(tosecond) forControlEvents:UIControlEventTouchUpInside];
   
    [self.view addSubview:button];
}

切换到下一个viewController

-(void)tosecond
{
    UIBarButtonItem * backItem=[[UIBarButtonItem alloc] initWithTitle:@"first" style:UIBarButtonItemStyleDone target:nil action:nil];//backButton不写也可以,默认就有
    self.navigationItem.backBarButtonItem=backItem;
    
    secondViewController *secondnavigationcontroller=[[secondViewController alloc] initWithNibName:@"secondViewController" bundle:nil];
    AppDelegate * appdelegate=[UIApplication sharedApplication].delegate;
[appdelegate.navigationcontroller pushViewController:secondnavigationcontroller animated:YES];//push新的ViewController进栈并显示出来
}

转帖:http://www.cnblogs.com/phoenix13suns/archive/2012/02/06/2340420.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值