开发者

Programmatically created grouped table view

I have created a grouped table view & I had a edit button in the title bar & I can 开发者_如何学运维able to navigate to other page on click of every row after pressing edit button

now by using following code I have designed the grouped table view programmatically but now edit button is not working on click of a row (after pressing edit) it's not navigating how can I fix this?

- (void)viewDidLoad {
    [super viewDidLoad];

    self.navigationItem.rightBarButtonItem = self.editButtonItem;

    tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 415)style:UITableViewStyleGrouped];
    tableView.dataSource = self;

    [self.view addSubview:tableView];
}


You're missing

tableView.delegate = self;


@Ruben is right. Set the delegate of the tableView and Implement the UITableViewDelegate methods


Side note - although developers do often assign the view controller as the datasource and delegate of a UITableView, you may want to consider farming these responsibilities out to another object.

UIViewController subclasses do have a habit of becoming so-called "god" classes, taking on lots of responsibilities (hence violating the Single Responsibility Principle) and also making them difficult to unit test.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜