![](/style/images/good.png)
![](/style/images/bad.png)
How to use a subclassed IB cell without reusing it?
source link: https://www.codesd.com/item/how-to-use-a-subclassed-ib-cell-without-reusing-it.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How to use a subclassed IB cell without reusing it?
I've created a cell with 2 UIButton
s in the IB and subclassed it. How can I use it without reusing it over again? (for a small fixed table) I tried doing something like: RaffleResultCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];
but that won't show my cell in the UITableView
, just a blank one.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//Where we configure the cell in each row
id currentRaffle = [_winnings objectAtIndex:indexPath.row];
RaffleResultCell *cell = [tableView dequeueReusableCellWithIdentifier:@"raffleResCell"];
if (cell == nil) {
cell = [[RaffleResultCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"raffleResCell"];
}
return cell;
}
It is not a good practice to avoid Reusability,I will say dont do it
Reusability is done in this line
RaffleResultCell *cell = [tableView dequeueReusableCellWithIdentifier:@"raffleResCell"];
Remove that line and just call alloc method everytime without the check loop
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
id currentRaffle = [_winnings objectAtIndex:indexPath.row];
cell = [[RaffleResultCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"raffleResCell"];
return cell;
}
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK