I am trying to set the background colour of particular cells in UITableViewCell to purple.
So far, I've tried this and it sets the colour of all the cells to purple instead of only the first cell.
In cellForRowAtIndexPath
method:
for(int k = 0; k < queueMCDate.count; k++){
if(_qbColorArr.count == 0) {
}
else if ([[_qbColorArr objectAtIndex:k] isEqual:@"a"]) {
if(indexPath.row == k)
cell.backgroundColor = [UIColor colorWithRed:0.48 green:0.04 blue:0.41 alpha:1.0];
}
}
return cell;
}
Here's a link showing how it currently looks right now.
How I would want the app to work is, after setting the return dates in the first cell, I would want it to be purple. By,
assigning a string value of a
to them, when I set the return dates, I was hoping that it would work.
Edit:
In cellForRowAtIndexPath
method :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
QueueDetails *cell = [tableView dequeueReusableCellWithIdentifier:@"reuCell" forIndexPath:indexPath];
cell.queueNo.text = fQueueNo[indexPath.row];
cell.queueeName.text = queueNameDisp[indexPath.row];
cell.bkTitle.text = queueBk[indexPath.row];
cell.dateRe.text = queueRDate[indexPath.row];
cell.dateBo.text = queueBDate[indexPath.row];
for(int k = 0; k < queueRDate.count; k++){
if(_qbColorArr.count == 0) {
cell.backgroundColor = [UIColor whiteColor];
return cell;
}
else if ([[_qbColorArr objectAtIndex:k] isEqual:@"a"]) {
if(indexPath.row == k)
cell.backgroundColor = [UIColor colorWithRed:0.48 green:0.04 blue:0.41 alpha:1.0];
return cell;
else{
cell.backgroundColor = [UIColor whiteColor];
return cell;
}
}
}
}
The cells would be at default white at the start, however when a return date is added to a cell, that cell would need to turn purple, indicating that a book has been returned, whilst the others stayed white.
To better clarify, the reason I used _qbColorArr
was because that the array contains either a blank (initialized at viewDidLoad
) or a
. So, when I set a return date to the first cell, I've also done this [_qbColorArr replaceObjectAtIndex:0 withObject:@"a"]
. This would then would be checked at the else if
statement and assign the color of the cell to purple.