Reputation: 482
I have an array like this in viewDidLoad
which contains UIColor
that would be used to fill table view cell background colour
self.ColorArray = [NSArray arrayWithObjects:
@"[UIColor redColor];",
@"[UIColor redColor];",
@"[UIColor redColor];", nil];
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
cell.contentView.backgroundColor = [self.ColorArray objectAtIndex: indexPath.row % self.ColorArray.count];
}
But this crashes away giving throws this error :
-[__NSCFConstantString CGColor]: unrecognized selector sent to instance 0x137b28 -
Upvotes: 1
Views: 885
Reputation: 1261
You are trying to pass color as string.
Try to pass as :
self.ColorArray = [NSArray arrayWithObjects:
[UIColor redColor],
[UIColor redColor],
[UIColor redColor], nil];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
cell.contentView.backgroundColor = [self.ColorArray objectAtIndex: indexPath.row % self.ColorArray.count];
}
Upvotes: 1
Reputation: 6282
You are initializing color array with String objects
Instead try adding UIColor
objects to the array
self.ColorArray = @[[UIColor whiteColor], @[UIColor redColor], @[UIColor grayColor]];
Upvotes: 0