简体   繁体   中英

numberofSections method not getting called by [tableview reloadData]

I am using xcode 5.0.2 . Its a UItabBarcontroller with 2 tabs with each tab having a navigation controller embedded programmatically in App Delegate . The problem might be a bit complex than it seems. I am using UIStoryboard . Is it something to do with autolayout being turned ON.

In 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];
}

In the firstViewController for the first tab I wanted to display a tableView . I created a IBOutlet for the tableView and its delegate and datasourc e are connected to the file owner.

In 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];
}

The tableView methods are not getting called. Only the viewDidLoad gets called. What should I change?

The second tab has a view-controller which shows a web-view . In the storyboard the segue is PUSH so I have to have a Navigationcontroller for the first VC.

1) you don't require to add TableView as a subview ( [self.view addSubview:_tableVC] ) if you already put it in your related .xib file

2) Have you check, you linked the added table view (of your .xib) with your table view's instance method tableVC ?

3) Have you include delegate, datasource headers in your .h file ie <UITableViewDatasource, UITableViewDelegate> ?

4) You dont need to reload table view in viewDidLoad . You always do reloadData where your datasource of your table view is change.

5) Have you implemented delegate function -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath to make your single cell according to your needs?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM