2015-04-23 51 views
0

我有一個奇怪的問題。XCode UITable滾動更改文本值

我加載在線數值並顯示在我的UITableViewCell中。它工作正常...我面臨的問題是,如果我向下滾動應用程序提取從網上相應,但當我向上滾動,值正確匹配...

如果strLocation不爲空我顯示如果strLocation爲空,我隱藏LocationImageView。當我最初加載應用程序時,這工作正常,當我滾動表格並向下移動時,如果某個值的空格爲strLocation,它隱藏了LocationImageView,但是在表格頂部的strLocation不爲空的情況下會發生什麼這些地方也LocationImageView被隱藏。

我想知道如何與細胞打交道時解決這個問題

cell.cityLabel.text = [dictionary valueForKey:@"location"]; 

NSString *strLocation = [dictionary valueForKey:@"location"]; 


if ([strLocation isEqual:@""]){ 
    cell.LocationImageView.hidden=TRUE; 
} 
+1

發佈更多驗證碼。特別是你應該發佈你的整個'tableView:cellForRowAtIndexPath:'方法。 – Dima

+0

它是一個大代碼,理解邏輯[cell setSelectionStyle:UITableViewCellSelectionStyleNone]會令人困惑;靜態NSString * simpleTableIdentifier = @「HomeTablecell」; cell =(HomeTableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; cell.vEdit.hidden = TRUE;如果(cell == nil) NSArray * nib = [[NSBundle mainBundle] loadNibNamed:@「HomeTableCell」owner:self options:nil]; cell = [nib objectAtIndex:0]; } NSDictionary * dictionary = [self.allPostArray objectAtIndex:indexPath.row]; –

+0

我已經給出部分代碼 –

回答

1

標準問題。 UITableView(如果正確使用)會重用細胞,因此您需要正確更新單元格。如果允許隱藏某個組件,則還需要放置一個代碼,以便在數據允許的情況下顯示該組件。看着你的代碼片段,你只是隱藏了組件,但沒有辦法讓它回來。

我猜看你的代碼,這樣做:

cell.LocationImageView.hidden=[strLocation isEqual:@""]; 

應該解決的問題。

+0

謝謝,這已經解決了我的問題:) –

+0

歡迎您,無論如何,我建議您查看UITableViewDelegate方法參考:)如果您可以請考慮upvoting。祝一切順利! –