我正在使用 xcode 5.0.2
。它是一个 UItabBarcontroller
,带有 2 个选项卡
,每个 tab
都有一个 navigation controller
以编程方式嵌入到 App Delegate
。这个问题可能比看起来有点复杂。我正在使用 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 和 datasource
e 连接到文件所有者。
在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 方法
未被调用。只有 viewDidLoad
被调用。我应该改变什么?
第二个选项卡
有一个view-controller
,它显示了一个web-view
。
在 Storyboard中,segue 是 PUSH,所以我必须为第一个 VC 设置一个 Navigationcontroller
。
最佳答案
1) 如果您已经将 TableView 添加到相关的 .xib 文件中,则不需要将其添加为 subview ( [self.view addSubview:_tableVC]
)
2) 您是否检查过,您是否将添加的 TableView (您的 .xib)与 TableView 的实例方法 tableVC 链接起来了?
3) 您是否在 .h 文件中包含委托(delegate)、数据源 header ,即 <UITableViewDatasource, UITableViewDelegate>
?
4) 你不需要在 viewDidLoad 中reload table view。你总是在你的 TableView 的数据源发生变化的地方做 reloadData。
5) 你有没有实现委托(delegate)函数 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 来根据你的需要制作你的单个单元格?
关于ios - [tableview reloadData] 未调用 numberofSections 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20393044/