각 행에 두 개의 변수가 포함되어 있고 서버에서 데이터를 가져 오는 것을 통해 매 2 초마다 새로 고치기 때문에 TableView
이 있습니다. 빨간색 또는 초록색이 높거나 낮 으면 모든 업데이트 색상을 변경하고 싶습니다. 그럼 내가 어떻게 할 수 있니? 라벨 색상을 변경하는 방법은 알고 있지만 각 2 초 사이에 압축하는 방법을 모릅니다.변수 사이의 비교 및 레이블 색상 변경
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"comCell";
comTableViewCell *cell = (comTableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
NSArray *parts = [[NSBundle mainBundle] loadNibNamed:@"comTableViewCell" owner:nil options:nil];
cell = [parts objectAtIndex:0];
}
id rowObject = [data1 objectAtIndex:indexPath.row];
[cell.lblType setText:[rowObject objectForKey:@"strSymbol"]];
[cell.lblOffer setText:[rowObject objectForKey:@"strOffer"]];
[cell.lblBid setText:[rowObject objectForKey:@"strBid"]];
cell.lblType.font = [UIFont fontWithName:@"Helvetica" size:12.0f];
cell.lblOffer.font = [UIFont fontWithName:@"Helvetica" size:12.0f];
cell.lblBid.font = [UIFont fontWithName:@"Helvetica" size:12.0f];
cell.lblType.textColor = [UIColor blackColor];
cell.lblOffer.textColor = [UIColor whiteColor];
cell.lblBid.textColor = [UIColor whiteColor];
return cell;
}
데이터 결과 :
{
strBid = "1.29158";
strOffer = "1.29258";
strSymbol = "USD/EUR";
},
{
strBid = "98.964";
strOffer = "99.004";
strSymbol = "AUD/JPY";
},
{
strBid = "11.2472";
strOffer = "11.2972";
strSymbol = "USD/ZAR";
}
업데이트 :
data2 = data1;
id rowObject2 = [data2 objectAtIndex:indexPath.row];
NSString *new_offer = [rowObject2 objectForKey:@"strOffer"];
if (data2 != nil) {
id old_rowObject = [data2 objectAtIndex:indexPath.row];
NSString *old_offer = [old_rowObject objectForKey:@"strOffer"];
if ([new_offer doubleValue] > [old_offer doubleValue]) {
cell.lblOffer.textColor = [UIColor greenColor];
cell.lblBid.textColor = [UIColor greenColor];
}
else if ([new_offer doubleValue] == [old_offer doubleValue]) {
cell.lblOffer.textColor = [UIColor blackColor];
cell.lblBid.textColor = [UIColor blackColor];
}
else {
cell.lblOffer.textColor = [UIColor redColor];
cell.lblBid.textColor = [UIColor redColor];
}
} else {
// first time getting data.
}
return cell;
}
당신이 당신의 데이터를 업데이트하는 코드를 공유하시기 바랍니다. –
'data1' 배열에 대한 데이터를 업데이트하고 있습니다. 나는 코드 – CAN
을 공유 할 것이다 또한 파싱 방법을 시작했다. – hasan83