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;
}
- (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;
}
...全文
相关推荐
tableview上加背景图片
一个简单的小程序 在window上加navigation navigation里 加tableView 用代码创建
UITableViewCell在编辑状态下背景颜色的修改方法
主要给大家介绍了关于UITableViewCell在编辑状态下背景颜色的修改方法,文中通过示例代码介绍的非常详细,对大家具有一定的参考学习价值,需要的朋友们下面跟着小编一起来学习学习吧。
ios-RoundTableviewCell.zip
类似于iPad设置的圆角tableview
滚动时背景模糊
tableView上滚动时背景模糊,下滚时背景清晰
IOS UITableView和NavigationBar的常用设置详解
IOS UITableView和NavigationBar的常用设置详解 TableView: 1.tableview常用基本设置 // 清除父类UIEdgeInsets self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 0,0); //禁止滚动 self.tableView.scrollEnabled = NO; // tableview头部视图设置 self.tableView.tableHeaderView =一个UIView; //tableview尾部视图设置,这样用一个不占空间的UIView初始化可以清除尾部多余空格 s


