Я пытаюсь создать подкласс UITableViewCell, который просто содержит свойство UILabel "nameLabel" и свойство UILabel "statusLabel". Для правильного удаления ячеек я реализовал метод cellForRowAtIndexPath: this:
PS: текст statusLabel взят из Twitter API, поэтому я должен отправить его размер [[UILabel alloc] initWithFrame:]
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
static NSString *CellIdentifier = @"StatusCellView";
StatusCellView *cell = [tableView dequeueReusableCellWithIdentifier:
CellIdentifier];
if (cell == nil) {
cell = [[StatusCellView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
for (UIView *subView in cell.contentView.subviews) {
[subView removeFromSuperview];
}
if (![cell viewWithTag:kNameLabelTag]) {
//init the nameLabel and [cell.contentView addsubview:nameLabel]
}
if (![cell viewWithTag:kStatusLabelTag]) {
//init the statusLabel and [cell.contentView addsubview:statusLabel]
}
return cell;
Как видите, это хорошо работает, когда данные не так велики.Но мой вопрос:
- Я думаю, что повторное удаление и добавление подпредставления ухудшит производительность.Это грубый способ ...
- Я могу реализовать ту же функцию без создания подкласса UITableViewCell.Есть ли способ использовать подкласс?