iOS-UItableViewセルでゴーストを除去する方法

780 ワード

法1.UItableViewセルでゴーストを除去する方法
cellForRowAtIndexPath:indexPathメソッドを使用して、cell再利用キューから取り出すのではなく、indexPathに従って行を正確に取り出します.
<span style="font-size:24px;">- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    // UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; //       
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; //  indexPath       ,    cell       
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
     //...                                  
}</span>
法二: