Keep UITableViewCell color when move UITableView rows
I have an UITableView, I set the color of the first row as Green.
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger row=[indexPath row];
NSInteger section=[indexPath section];
static NSString *SimpleTableIdentifier1 = @"CellTableIdentifier";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier: SimpleTableIdentifier1 ];
if (cell == nil) {
cell=[[[UITab开发者_开发知识库leViewCell alloc] initWithFrame:CGRectZero//SimpleTableIdentifier1
reuseIdentifier:nil] autorelease];
}
//------------------------------------------------
if(row==0)
{
//green color
[cell setBackgroundColor:[UIColor colorWithRed:0.10f green:0.95f blue:0.1f alpha:1.0f]];
}
else //white color
[cell setBackgroundColor:[UIColor colorWithRed:0.90f green:0.95f blue:1.0f alpha:1.0f]];
return cell;
}
even if I move the rows, I still hope the first row color is Green, so I set codes as:
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
[tableview reloadData];
}
but it reports 'Program received signal: “EXC_BAD_ACCESS”.'
Welcome any comment
Thanks
use tableView delegate method
- (void)tableView: (UITableView*)tableView willDisplayCell: (UITableViewCell*)cell forRowAtIndexPath: (NSIndexPath*)indexPath {
if(row==0)
{
//green color
[cell setBackgroundColor:[UIColor colorWithRed:0.10f green:0.95f blue:0.1f alpha:1.0f]];
}
else
//white color
[cell setBackgroundColor:[UIColor colorWithRed:0.90f green:0.95f blue:1.0f alpha:1.0f]];
}
精彩评论