开发中使用到UITableView的各个技术点

     直接上代码,进行注释,更加明了

     - (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

   // 设置标题
    self.navigationItem.title = @"我的";

    //设置视图的背景图片
    UIImage *backG = [UIImage imageNamed:@"250"];
    self.view.layer.contents = (__bridge id)(backG.CGImage);
    
   #ifdef moreThanIOS7

   //iOS7之后视图view从最顶点(0,0,0,0)开始。设置以后属性之后,与iOS7之前一致,从UINavigationBar下面开始

    self.edgesForExtendedLayout = UIRectEdgeNone;

   #endif

    //设置头像以及最新轻博客图片及内容
    [self headImageView];
   

    //注意要设置属性为UITableViewStyleGrouped,才能是设置多个section,如果继承于UITableViewController,默认是UITableViewStylePlain,无法设置多个section
     tableV = [[UITableView alloc]initWithFrame:CGRectMake(0,headImg.frame.size.height,ScreenWidth,Screenheight-headImg.frame.size.height-49) style:UITableViewStyleGrouped];
    tableV.delegate = self;
    tableV.dataSource = self;

   //设置该属性,tableview无法滚动
//    _tableV.scrollEnabled = NO;
    [self.view addSubview:tableV];
    
    tipsDic = [[NSDictionary alloc]initWithObjectsAndKeys:[NSArray arrayWithObjects:@"基本资料",@"证件认证",@"我的相册", nil],@"0",[NSArray arrayWithObjects:@"一对一授课",@"开班授课",@"授课区域",nil],@"1",[NSArray arrayWithObjects:@"我的信用",@"我的学生",nil],@"2",[NSArray arrayWithObjects:@"邀请入驻",@"账号设置",@"清除缓存",@"意见反馈",@"关于我们", nil],@"3", nil];
    
}
-(void)headImageView
{
    CGFloat headHeight = 150;
    headImg = [[UIImageView alloc]initWithFrame:CGRectMake(0,0, ScreenWidth, headHeight)];
    headImg.userInteractionEnabled = YES;
    
    CGFloat porWidth = 60;
    CGFloat porheight = 60;
    CGFloat xGap = 20;
    CGFloat yGap = 10;
    portrait = [[UIImageView alloc]initWithFrame:CGRectMake(xGap, headHeight-porheight-yGap, porWidth, porheight)];
    [headImg addSubview:portrait];
    
    CGFloat wordwidth = ScreenWidth-porWidth-3*xGap;
    CGFloat wordheight = 60;
    words = [[UILabel alloc]initWithFrame:CGRectMake(xGap+porWidth+xGap,headHeight-wordheight-yGap, wordwidth, wordheight)];
    words.backgroundColor = [UIColor clearColor];
    words.textColor = [UIColor whiteColor];
    [headImg addSubview:words];
    
    [self.view addSubview:headImg];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 4;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    switch (section) {
        case 0:
            return 3;
            break;
        case 1:
            return 3;
            break;
        case 2:
            return 2;
            break;
        default:
            return 5;
            break;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 30.0f;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{

    //设置每个section的headerview高度

    return 10.0f;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{

    //设置每个section的footerview高度
    return 5.0f;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *cellIdentifier = @"information";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }

    //选区cell没有点击效果
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    //固定图片的大小
    CGSize itemsize = CGSizeMake(20, 20);
    UIGraphicsBeginImageContext(itemsize);
    CGRect imageRect = CGRectMake(0.0, 0.0, itemsize.width, itemsize.height);
    [cell.imageView.image drawInRect:imageRect];
    cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    cell.imageView.image = [UIImage imageNamed:@"pic"];
    
    cell.textLabel.text = [[tipsDic objectForKey:[NSString stringWithFormat:@"%ld",indexPath.section]] objectAtIndex:indexPath.row];

    //cell右侧指示标志(右箭头标志)
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值