简体   繁体   中英

UITableViewDelegate method not getting called

I used IB to create a UITableViewController in Storyboard. And I set the UITableview's delegate to be its controller. The UITableView has static cells. Just 2 sections. First section has 3 non-selectable rows. And last section has 1 row which is selectable. I set this all in IB only.

Then I implemented this method in the UITableViewController.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"SELECTED");

    if (indexPath.section == 1 && indexPath.row == 0) {
        //login and report the result
        [self login];
    }
}

When I select the only row in the 2nd section, this above method is not getting called. What could have gone wrong. I have double checked the delegate setups in outlets inspector of UITableView as well. Everything is fine!

Just do this: Control drag you tableView from Storyboard to viewcontroller .h file, create @property for ex. tableView. Add again to .h file. Then in .m file in viewDidLoad write this:

    -(void)viewDidLoad{
       //your other code
       self.tableView.delegate = self;
       self.tableView.dataSource = self;
       //other code ...
     }

I prefer to use tblView for property name, because you will see warning that tableView hides instance. Hope this help.

Do you see the NSLog statement in the console? How about in viewDidAppear, NSLog(@"Delegate: %@",tableView.delegate)

See if you're getting NULL in the console.

You know that the dataSource is connected right, or else you wouldn't have any cells visible. It's got to be your delegate connection =)

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