簡體   English   中英

IOS UItableview reloadRowsAtIndexPaths刷新問題

[英]IOS UItableview reloadRowsAtIndexPaths refresh issue

我想更新到tableview自定義單元格。 當我搜索時,我想刷新表格單元格。 我使用reloadRowsAtIndexPaths方法。 這種方法有效,但沒有更新單元格。 你能幫我嗎

下面的方法運行當我搜索

-(void)doSearchHotelName:(id)sender{

    NSIndexPath *tmpIndexpath=[NSIndexPath indexPathForRow:1 inSection:0];

    [self.tableV beginUpdates];
    [self.tableV reloadRowsAtIndexPaths:[NSArray arrayWithObjects:tmpIndexpath, nil] withRowAnimation:UITableViewRowAnimationFade];
    [self.tableV endUpdates];

}

方法表方法下面

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

    Hotel_FilterSearchCell_iPad *cell = (Hotel_FilterSearchCell_iPad *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];




    if (cell == nil) 
    {
        NSArray *nib ;

        nib = [[NSBundle mainBundle] loadNibNamed:@"Hotel_FilterSearchCell_iPad" owner:self options:nil];

        cell = [nib objectAtIndex:0];
    }

    else if ([indexPath row]==1) {


        if([SharedAppDelegate.filter_selected_hotels_list count]==[SharedAppDelegate.filter_hotels_list count])

            [cell.cellExtraInfo setText:@"All(H)"];

        else if ([SharedAppDelegate.filter_selected_hotels_list count]!=[SharedAppDelegate.filter_hotels_list count])  

            [cell.cellExtraInfo setText:[NSString stringWithFormat:@"%i %@",[SharedAppDelegate.filter_selected_hotels_list count],@"Selected(H)"]];

    }

    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    return cell;
}
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationAutomatic];

嘗試將UITableViewRowAnimationFade更改為UITableViewRowAnimationNone ,如果有幫助,請告訴我。

我只是必須這樣做,因為我在我的故事板中使用靜態UITableView,似乎任何動畫都將舊單元格移出視圖並替換為新單元格。 這基本上從表中刪除了單元格,因為舊單元格和新單元格是同一個對象(我的假設)。

從UITableView 文檔

beginUpdates
開始一系列方法調用,插入,刪除或選擇接收器的行和部分。

除非要插入,刪除或選擇行或節,否則不應使用此方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM