Setting style of UITableViewCell when using iOS 6 UITableView dequeueReusableCellWithIdentifier:forIndexPath:

后端 未结 6 1797
庸人自扰
庸人自扰 2020-12-02 07:28

I\'m trying to work out how to set the UITableViewCellStyle when using the new methods in iOS 6 for UITableView.

Previously, when creating

6条回答
  •  粉色の甜心
    2020-12-02 07:38

    My solution to this is to call initWithStyle: reuseIdentifier: after I've obtained it using [self.tableView dequeueReusableCellWithIdentifier:@"cellId" forIndexPath:indexPath]. After all, init is just another selector, and the compiler makes no restrictions on calling it on an already initialised object. It will however complain about not using the result of calling init, so I do:

    UITableViewCell* cell = [self.tableView dequeueReusableCellWithIdentifier:@"cellId" forIndexPath:indexPath];
    cell = [cell initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cellId"];
    

    I imagine this won't work in Swift...

提交回复
热议问题