zoukankan      html  css  js  c++  java
  • 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进栈并显示出来
    }




  • 相关阅读:
    MySQL 待解决死锁
    MySQL5.7 服务 crash 后无法启动
    MySQL Group Replication
    MySQL容量规划之tcpcopy应用之道
    Python模块安装路径初探
    MySQL5.7多源复制实践
    Mysql中两个select语句的连接
    ThinkPhp sql语句执行方法
    TP框架如何绑定参数。目的进行ajax验证
    jquery 复合事件 toggle()方法的使用
  • 原文地址:https://www.cnblogs.com/phoenix13suns/p/2340420.html
Copyright © 2011-2022 走看看