Я хочу изменить цвет текста ячеек в UITableView.Изменение цвета текстовой ячейки на основе ее значения
Когда я пытаюсь сделать условное форматирование с использованием if
, он не работает.
Вот код, который я пытаюсь:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return nomearray.count;
}
- (void)tableView: (UITableView*)tableView willDisplayCell: (UITableViewCell*)cell forRowAtIndexPath: (NSIndexPath*)indexPath
{
cell.textLabel.textAlignment = UITextAlignmentRight;
if(indexPath.row % 2 == 0) {
cell.backgroundColor = [UIColor colorWithRed:(240/255.0) green:(240/255.0) blue:(240/255.0) alpha:1];}
else {
cell.backgroundColor = [UIColor whiteColor];}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleTableItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
if (risco == 1) {[cell.textLabel setTextColor: [UIColor colorWithRed:(60/255.0) green:(169/255.0) blue:(133/255.0) alpha:1]];} else {
if (risco == 2) {[cell.textLabel setTextColor: [UIColor colorWithRed:(255/255.0) green:(200/255.0) blue:(0/255.0) alpha:1]];} else {
if (risco == 3) {[cell.textLabel setTextColor: [UIColor colorWithRed:(150/255.0) green:(50/255.0) blue:(50/255.0) alpha:1]];}}}
cell.textLabel.text = [nomearray objectAtIndex:indexPath.row];
return cell;
}
что такое risco? – incmiko
И где этот код? В каком методе? – sha
risco - целочисленная переменная, ведьма может принимать 3 значения, 1, 2 или 3. Я хочу, чтобы цвет текста в ячейках менялся в зависимости от значения этого var (risco) – user3093398