Chinaunix首页 | 论坛 | 博客
  • 博客访问: 306398
  • 博文数量: 53
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 325
  • 用 户 组: 普通用户
  • 注册时间: 2013-10-14 22:50
文章分类

全部博文(53)

文章存档

2014年(15)

2013年(38)

我的朋友

分类: iOS平台

2013-11-28 10:20:17

TableViewAppDelegate.m

  1. #import "TableViewAppDelegate.h" 
  2. #import "TableViewController.h" 
  3. @implementation TableViewAppDelegate
  4. @synthesize window = _window;

  5. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions    
  6. {
  7. NSMutableArray *controllers = [NSMutableArray array];
  8. NSArray *item = [NSArray arrayWithObjects:@"雨松MOMO",@"若若娃",@"小可爱",@"哇咔咔",@"小老虎",@"学苹果",@"快乐乐",@"寿司卷", nil];
  9. //数组数量
  10. int count = [item count];
  11. for (int i = 0; i < count; i++)
  12. {
  13. //创建TableViewController
  14. TableViewController * tabViewController = [[TableViewController alloc]initController:[item objectAtIndex:i]];

  15. //设置标题
  16. [tabViewController setTitle:@"雨松MOMO的程序世界"];

  17. //绑定tabViewController用来响应按钮点击事件
  18. UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:tabViewController];

  19. //设置标题
  20. nav.title = [item objectAtIndex:i];

  21. //设置图片
  22. nav.tabBarItem.image = [UIImage imageNamed:@"title.png"];
  23. //设置风格为默认风格
  24. nav.navigationBar.barStyle = UIBarStyleDefault;

  25. //添加这个UINavigationController
  26. [controllers addObject:nav];

  27. //释放对象
  28. [nav release];
  29. }

  30. //创建UITabBarController,将显示的内容添加进去
  31. UITabBarController *bar = [[UITabBarController alloc] init];
  32. bar.viewControllers = controllers;
  33. bar.customizableViewControllers = controllers;

  34. //添加到显示窗口中
  35. [self.window addSubview:bar.view];
  36. // Override point for customization after application launch.
  37. [self.window makeKeyAndVisible];
  38. return YES;
  39. }
  40. @end    


如下图所示,多余的Item会以列表的形式展示。






阅读(433) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~