Reputation: 3921
Is it safe to setup a UITableViewCell in a xib file, connect it to an IBOutlet property, and return it in cellForRowAtIndexPath?
In theory, I don't see a problem with it assuming the cell in question is not meant to be reusable. In practice, I don't really like doing it this way, but... is there actually a technical problem doing it this way?
@interface MyTableViewController()
{
@property (nonatomic, strong) IBOutlet UITableViewCell *myCell;
}
....
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.section == 0 && indexPath.row == 0)
{
return myCell;
}
// else create some other cell manually and return it
}
Edit: I would like to clarify that this is not a stylistic question; I have already decided I am not a fan of this style. It is simply a question asking if doing it this way can have unforeseen consequences, perhaps if a view is recreated or something.
Upvotes: 2
Views: 119
Reputation: 3746
As long as this cell appears only once in the table, there is no problem with this approach.
Upvotes: 2
Reputation: 4413
There is a big problem with doing it this way because you will only be returning a single cell. Most importantly this would be returning the same cell. The better way to use an nib file to define a tableviewcell is to use the registerNib:forCellReuseIdentifier:
method of UITableView.
Upvotes: 1