2016-04-11 66 views
0

我知道這個問題已經被問了很多次了,但是沒有一個答案對我有用。當我向下滾動UITableView然後向上滾動時,單元格內容會發生變化,並且看起來像是另一個單元格內容。我如何解決這個問題,如果可以提供一個很好的代碼示例。這裏是一個答案我想是有道理的,但我不知道如何實現:Link當在UITableview中滾動時,單元格發生變化

這裏是我的代碼有

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 


    SearchedCell *cell = (SearchedCell *)[tableView dequeueReusableCellWithIdentifier:@"any-cell"]; 

    if (!cell) 
    { 
     cell = [[SearchedCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"any-cell"]; 
    } 


    NSDictionary *dict = [[appDel.jsonDict valueForKey:@"results"] objectAtIndex:indexPath.row]; 

    if([dict valueForKey:@"BusinessUrl"] == nil) 
    { 
    cell.btnMenu.hidden = TRUE; 
    } 
    else 
    { 
    cell.btnMenu.hidden = FALSE; 
    } 

    cell.lblRestaurantName.text = [dict valueForKey:@"name"]; 

    NSString *tmpAddr = [dict valueForKey:kResponseVicinity]; 
    cell.lblAddress.text = tmpAddr; 
    if(appDel.isNearClicked) 
    { 
     cell.lblDistance.text = @""; 
    } 
    else 
    { 
    cell.lblDistance.text = @""; 
    } 
    cell.lblPhoneNo.text = [dict valueForKey:@"Phone"]; 

    [cell.btnCall addTarget:self action:@selector(CallClicked:) forControlEvents:UIControlEventTouchUpInside]; 
    [cell.btnMap addTarget:self action:@selector(MapClicked:) forControlEvents:UIControlEventTouchUpInside]; 
    [cell.btnMenu addTarget:self action:@selector(MenuClicked:) forControlEvents:UIControlEventTouchUpInside]; 
    cell.btnCall.tag = indexPath.row; 
    cell.btnMap.tag = indexPath.row; 
    cell.btnMenu.tag = indexPath.row; 

    return cell; 

} 
+0

什麼內容都在改變? – Krish

+0

評級正在改變。它顯示了一個值,然後當我向下滾動並向上滾動時,它顯示出不同的值。 –

+0

您是否更新模型中的評分? – Krish

回答

-1

你必須做這樣的事情: -

-(NSArray *)SetSelectionArray:(NSArray *)OldArray :(NSUInteger)index 
{ 

NSMutableArray *TempArr=[[NSMutableArray alloc] init]; 
NSMutableDictionary *modifyDict=[[OldArray objectAtIndex:index] mutableCopy]; 
if ([[modifyDict valueForKey:@"selectionState"]isEqualToString:@"1"]) 
{ 
    [modifyDict setValue:@"0" forKey:@"selectionState"]; 
} 
else 
{ 
    [modifyDict setValue:@"1" forKey:@"selectionState"]; 
} 

TempArr=[OldArray mutableCopy]; 
[TempArr replaceObjectAtIndex:index withObject:modifyDict]; 
return [TempArr copy]; 

}

+0

我不明白這是如何與問題相關的,更不用說提供答案了 – Lasse

1

您需要在自定義單元類中實現prepareForReuse

相關問題