星空网 > 软件开发 > 操作系统

iOS UITableview

1. UITableView

//去除tableviews的点击效果

cell.selectionStyle = UITableViewCellSelectionStyleNone;
 
 //隐藏tableView的分割线
cell.tableView.separatorStyle = UITableViewCellSelectionStyleNone;
 
//根据cell的位置获得某个cell
SecondTableViewCell *cell = (SecondTableViewCell *)[self.tableViewcellForRowAtIndexPath:[NSIndexPathindexPathForRow:2inSection:0]];
 
//设置行高为动态
tableView.rowHeight = UITableViewAutomaticDimension;
 
//cell的预估行高
tableView.estimatedRowHeight = 44;
点击状态栏回到顶部
tableView.scrollsToTop = YES;

 
//刷新一个section
NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:2]; 
[tableview reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];      
//一个cell刷新    
NSIndexPath *indexPath=[NSIndexPath indexPathForRow:3 inSection:0];
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
 
实现这个新的delegate函数即可:可以设置背景色
- (void)tableView:(UITableView *)tableView willDisplayFooterView:(UIView *)view forSection:(NSInteger)section { view.tintColor = [UIColor clearColor]; }
改变文字的颜色
- (void)tableView:(UITableView *)tableView willDisplayFooterView:(UIView *)view forSection:(NSInteger)section { UITableViewHeaderFooterView *footer = (UITableViewHeaderFooterView *)view; [footer.textLabel setTextColor:[UIColor whiteColor]]; }

 
cell的4种格式
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell;
    switch (indexPath.row) {
        case 0:
        {
            cell =[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CELL1];
            cell.backgroundColor = [UIColor yellowColor];
            cell.selectionStyle = UITableViewCellSelectionStyleDefault;
        }
            break;
        case 1:
        {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CELL2];
            cell.backgroundColor = [UIColor redColor];
            cell.selectionStyle = UITableViewCellSelectionStyleGray;
        }
            break;
        case 2:
        {
            cell =[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CELL2];
            cell.backgroundColor = [UIColor blueColor];
            cell.selectionStyle = UITableViewCellSelectionStyleBlue;
        }
            break;
        case 3:
        {
            cell =[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CELL4];
            cell.backgroundColor = [UIColor purpleColor];
            cell.selectionStyle = UITableViewCellSelectionStyleDefault;
        }
            break;
    }
    cell.imageView.image = [UIImage imageNamed:@"warning_btn"];
    cell.detailTextLabel.text = @"detailTextLabel";
    cell.textLabel.text = @"textLabel";
    return cell;
}
iOS UITableview


  
 





原标题:iOS UITableview

关键词:IOS

IOS
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流