2013-12-11 4 views
0

Я пытаюсь добавить Load More Cell в свой рабочий стол. Начните с 5 строк, и когда я нажму «Load More Cell» и добавлю еще 5 строк. Все работает нормально, без загрузки больше ячейки имеет изображение, но я не хочу этого. Я попытался исправить это, но это не сработает.Загрузить дополнительную ячейку UITableView

Таблица начать http://i.stack.imgur.com/Ld2ED.png

таблицу после нажмите Load More Cell http://i.stack.imgur.com/A5xjE.png

Вот мой cellForRowAtIndexPath:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 

#define IMAGE_VIEW_TAG 99 
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (indexPath.section == 0) { 
     //create new cell 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
     //add AsyncImageView to cell 
     AsyncImageView *imageView = [[AsyncImageView alloc] initWithFrame:CGRectMake(5.0f, 5.0f, 50.0f, 50.0f)]; 
     imageView.contentMode = UIViewContentModeScaleAspectFill; 
     imageView.clipsToBounds = YES; 
     imageView.tag = IMAGE_VIEW_TAG; 
     [cell addSubview:imageView]; 
     [imageView release]; 

     //common settings 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 
     cell.accessoryType = UITableViewCellAccessoryNone; 
     cell.indentationWidth = 44.0f; 
     cell.indentationLevel = 1; 
     //get image view 
     AsyncImageView *imgView = (AsyncImageView *)[cell viewWithTag:IMAGE_VIEW_TAG]; 

     //cancel loading previous image for cell 
     [[AsyncImageLoader sharedLoader] cancelLoadingImagesForTarget:imgView]; 

     //load the image 

     imgView.imageURL = [imageURLs objectAtIndex:indexPath.row]; 

     //display image path 
     cell.textLabel.text = [tableData objectAtIndex:indexPath.row ]; 


    } 


    else if (indexPath.section == 1) { 

     cell.textLabel.text = [NSString stringWithFormat:NSLocalizedString(@"Load More...", @"The text to display to load more content"), kNumberOfItemsToAdd]; 
     cell.imageView.image = Nil; 
     cell.textLabel.textColor = [UIColor colorWithRed:0.196f green:0.3098f blue:0.52f alpha:1.f]; 
     cell.textLabel.font = [UIFont boldSystemFontOfSize:12.f]; 

    } 

numberOfSection

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    if (numberOfItemsToDisplay == [tableData count]) { 
     return 1; 
    } 
    return 2; 
} 



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
// return 5; 
// return tableData.count; 
    if (section == 0) { 
     return numberOfItemsToDisplay; 
    } else { 
     return 1; 
    } 


} 
+0

Найдите способ обнаружения «Загрузить больше» ячейку таблицы, а затем установить ImageView к нулю – rocky

+0

я установить cell.imageView.image = Nil; , но в ячейке «Загрузить больше» все еще есть изображение –

+0

вы можете обновить свой код, чтобы отразить изменения, упомянутые в вашем комментарии? – rocky

ответ

1

заменить это:

else if (indexPath.section == 1) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    ... 
    ... 
    ... 
} 
+0

спасибо вам большое! Я не думал, что это так просто –

+0

вы можете отметить это как правильный ответ? – rocky

+0

спасибо, и ты рад =) – rocky

Смежные вопросы