UITableView 设置BackGroundView ?
以下代码,运行结果正确, 所有cell的背景图都替换成功。可是当我把UIView *view = [[UIView alloc]init];view.backgroundColor =[UIColor redColor]; 这两行代码移道Viewdidload()中,并且将view定义成我的类的成员变量。再在cellForRowAtIndexPath:函数中将cell的backgroupview = _view;这样一改后,为什么每次只有最后一个cell的背景图可以替换成功,其余的背景图都替换不了,求解决办法,我不想每次都在cellForRowAtIndexPath alloc一个view,那样效率太低了?
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell * Cell1 =[tableView dequeueReusableCellWithIdentifier: @"PlanCell"];
NSArray *array =[NSArray arrayWithObjects:@"相序方案",@"配时方案",@"周方案",@"假日方案",
@"时间方案",@"感应方案",nil];
Cell1.selectionStyle = UITableViewCellSelectionStyleBlue;
Cell1.textLabel.text = [array objectAtIndex:indexPath.row];;
Cell1.textLabel.font = [UIFont fontWithName:@"Helvetica" size:20];
UIImageView *view = [[UIView alloc]init];
view.backgroundColor =[UIColor redColor];
Cell1.backgroundView = view;
return Cell1;
}