【发布时间】:2013-12-05 06:29:34
【问题描述】:
我正在使用xcode 5.0.2。它是一个UItabBarcontroller 和2 tabs,每个tab 在App Delegate 中以编程方式嵌入一个navigation controller。这个问题可能比看起来要复杂一些。我正在使用UIStoryboard。是否与打开自动布局有关。
在AppDelegate.m
in didFinishLaunchingMethod
{
self.tabBarController=[[UITabBarController alloc]init];
AIFirstViewController *viewController1 = [[AIFirstViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController *navigationController1 = [[UINavigationController alloc] initWithRootViewController:viewController1];
viewController1.title = @"Menu";
AISecondViewController *viewController2 = [[AISecondViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController *navigationController2 = [[UINavigationController alloc] initWithRootViewController:viewController2];
viewController2.title = @"Search";
self.tabBarController.viewControllers=[NSArray arrayWithObjects:navigationController1, navigationController2, nil];
[self.window setRootViewController:_tabBarController];
[self.window makeKeyAndVisible];
}
在第一个选项卡的firstViewController 中,我想显示tableView。我为tableView 创建了一个IBOutlet,它的delegate and datasource 连接到文件所有者。
在AIFirstViewConroller.m
-(void)viewDidLoad
{
[super viewDidLoad];
self.tableVC.delegate = self;
self.tableVC.dataSource=self;
_checklist = [[NSMutableArray alloc] initWithObjects:@"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9", nil];
NSLog(@"the tableview object: %@", self.tableVC);
[self.view addSubview:_tableVC];
[self.tableVC reloadData];
}
-(void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
[self.tableVC reloadData];
}
numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [_checklist count];
}
tableView methods 没有被调用。只有viewDidLoad 被调用。我应该改变什么?
second tab 有一个view-controller,它显示一个web-view。
在情节提要中,segue 是 PUSH,所以我必须为第一个 VC 提供 Navigationcontroller。
【问题讨论】:
-
@βḧäṙℊặṿῗ:见 viewDidLoad 中的第二行
-
只是一点:你不需要这样做:[self.view addSubview:_tableVC];如果你已经有 nib 的 IBOutlet。
-
你的 .h 文件中有类似 :@interface AIFirstViewConroller : UIView
的东西吗? -
顺便说一句,你正在做很多 reloadData !!,你不需要在 viewDidLoad 中这样做。
-
如果您使用故事板,为什么要使用 initWithNibName:bundle: 来实例化您的控制器?
标签: ios uinavigationcontroller uitabbarcontroller uitableview