tableView returns null

Discussion in 'iOS Programming' started by Edje09, Aug 30, 2015.

  1. Edje09 macrumors newbie

    Aug 30, 2015
    I'm writing an app with 3 views - two hierarchical table views followed by a content page. The content in the final page is populated by the data stored in a variable that is determined by the row clicked in the second table view. As it stands, both tables populate with data fine, and the final page's content is populated fine as well, but every time acts as if the user clicked the first row, regardless of which row as actually pressed. This is the code for the segue from the second table view to the content view:

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
        if ([segue.identifier isEqualToString:@"showUSViewDetail"]) {
            NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
            NSLog(@"%@", self.tableView);
            USDetailViewController *destViewController = segue.destinationViewController;
            NSString *currentSelection = [examDetailViewContents objectAtIndex:indexPath.row];
            destViewController.usView = [views objectForKey:currentSelection];
    From my debugging so far, what I've realized is that self.tableView returns null. I assume what happens is that the view presumes the row is 0 and uses the data generated by the first row. I've got a global variable in this file called tableView, which is defined:

    @property (nonatomic, strong) IBOutletUITableView *tableView; // from the .h file

    @synthesize tableView; // from the .m file
    The weird part is that the segue from the first to second table view is managed with almost identical code, and it works just fine. Any thoughts? Thanks in advance.
  2. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    Are you using a UITableViewController? If so it has its own tableView property and you don't need your own.
    If not, you should check if self.tableView is nil in viewDidLoad. Either the IBOutlet isn't set or you're setting it to nil somewhere in your code. Most likely the IBOutlet isn't set in the storyboard.

    BTW, you should place IBOutlet declarations in .m file, not the .h file.
    @synthesize isn't required anymore in most cases.
  3. Edje09 thread starter macrumors newbie

    Aug 30, 2015
    As always, it's something tiny but crucial. I somehow managed to not set the IBOutlet, so it was null from the start. Works perfectly now. You are amazing and I love you.

Share This Page