У меня есть UITableView с пользовательским представлением. Для нижней части таблицы, я добавляю туда ячейку «Загрузить еще». После того, как щелкнул, таблица просмотрела больше данных, а ячейка «Загрузить еще» - в нижней части таблицы. Однако после того, как я щелкнул первую «Загрузить больше», появится вторая «Загрузить больше», и пользовательский вид все еще существует в той же ячейке второй «Загрузить больше». «Загрузить больше» и пользовательский вид находятся в одной ячейке. Я хочу, чтобы эта ячейка появилась только «Загрузить больше».Пользовательский вид UITableView и «Загрузить больше» в той же ячейке
Эта проблема существует для третьего, четвертого «Загрузить больше». Может ли кто-нибудь мне помочь?
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return imageCurPos+1;
}
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if([aTableView tag]==501){
// Main Table
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
[[cell viewWithTag:3007] removeFromSuperview];
const NSInteger BOTTOM_LABEL_TAG = 3002;
UIImageView *bottomLabel;
UILabel *loadMore;
if(indexPath.row < imageCurPos){
if (cell == nil)
{ //All repeat things come here, if don't want to repeat here, please state outside this brucket
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
//Edited
for (UIView *view in [cell.contentView subviews])
{
[view removeFromSuperview];
}
bottomLabel = [[[UIImageView alloc] initWithFrame: CGRectMake(50, 30, 250, 112)] autorelease];
[cell.contentView addSubview:bottomLabel];
bottomLabel.tag = BOTTOM_LABEL_TAG;
cell.backgroundView =
[[[UIImageView alloc] init] autorelease];
cell.selectedBackgroundView =
[[[UIImageView alloc] init] autorelease];
UIImageView *iconView = [[[UIImageView alloc] initWithFrame:CGRectMake(0, 30, 45, 45)] autorelease];
iconView.image = [UIImage imageNamed:@"02_bubble.png"];
[[cell contentView] addSubview:iconView];
bottomLabel.image = [UIImage imageNamed:@"05_bubble.png"];
}else if(indexPath.row == imageCurPos){ //For Load More
if (cell == nil)
{ //All repeat things come here, if don't want to repeat here, please state outside this brucket
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
//Edited
for (UIView *view in [cell.contentView subviews])
{
[view removeFromSuperview];
}
loadMore =
[[[UILabel alloc]
initWithFrame:
CGRectMake(0, 0, 300, 50)]
autorelease];
loadMore.text = @"Load more...";
loadMore.textAlignment = UITextAlignmentCenter;
loadMore.tag = 3007;
loadMore.textColor = [UIColor whiteColor];
loadMore.backgroundColor = [UIColor darkTextColor];
[cell.contentView addSubview:loadMore];
}
return cell;
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *) indexPath{
if([tableView tag]==501){
if([indexPath row] != imageCurPos){
}else{ // For load more
NSLog(@"noRow Prev: %d", imageCurPos);
imageCurPos += interval;
NSLog(@"noRow After: %d", imageCurPos);
[tbl_mo_main reloadData];
}
}
Спасибо, я попробовал это, но это дало мне ошибку EXC_BAD_ACCESS. Я боролся с этим в течение двух дней. –
обновите свой код с внесенными вами изменениями, а также выполните NSLog в начале метода, чтобы проверить, какой путь указателя указан сбой – Shubhank
Я просто добавил код ниже под (cell == nil), он сработает после нажатия на Load Подробнее, обновлено в Вопросе для (UIView * view в [cell.contentView subviews]) { [просмотреть removeFromSuperview]; } –