我有一個tableview,每10秒刷新一次新的double值,我需要一種機制來比較當前值和以前的值,但是我沒有正確地做到這一點。Objc如何在tableview單元格中比較當前值和前一個double值
這是我現在擁有的。你能否建議如何存儲當前/以前的值,以在刷新後得到比較結果。你的情況在tempDictionary - 提前
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell;
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifierCell forIndexPath:indexPath];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifierCell];
}
Value = [[tempDictionary objectForKey:@"value"] doubleValue];
if (ValueCurrent > ValuePrevious && ValuePrevious !=0.0) {
Label.backgroundColor = [UIColor greenColor];
}
if (ValueCurrent < ValuePrevious) {
Label.backgroundColor = [UIColor redColor];
}
ValuePrevious = Value;
return cell;
}
'cellForRowAtIndexPath'對於任何與單元格顯示沒有直接關係的邏輯來說都是錯誤的地方。特別是'ValuePrevious = Value;'在該位置絕對是錯誤的。並且請更改所有變量以小寫字母開頭。 – luk2302