码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 使用tableView实现 个人中心列表

时间:2015-06-17 13:27:49      阅读:2726      评论:0      收藏:0      [点我收藏+]

标签:uitableview   个人中心   列表   微信   界面   

类似于微信的个人中心 可以使用UITableViewl来实现。

最终效果

技术分享


直接上代码


首先使

UIViewController

实现协议 

UITableViewDataSource,UITableViewDelegate

创建两个属性


   UITableView *personalTableView;

    NSArray *dataSource;

    



@interface UserInfoViewController ()<UITableViewDataSource,UITableViewDelegate>
{
    UITableView *personalTableView;
    NSArray *dataSource;
    
}


初始化


 personalTableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 44+20, SCREEN_WIDTH, SCREEN_HEIGHT-20-44-49) style:UITableViewStyleGrouped];
    [self.view addSubview:personalTableView];
    personalTableView.delegate=self;
    personalTableView.dataSource=self;
    personalTableView.bounces=NO;
    personalTableView.showsVerticalScrollIndicator = NO;//不显示右侧滑块
    personalTableView.separatorStyle=UITableViewCellSeparatorStyleSingleLine;//分割线
    dataSource=@[@"我的分享",@"密码管理",@"用户协议",@"关于"];

实现一下几个代理


#pragma mark tableViewDelegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    //分组数 也就是section数
    return 3;
}

//设置每个分组下tableview的行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section==0) {
        return 1;
    }else if (section==1) {
        return dataSource.count;
    }else{
        return 1;
    }
}
//每个分组上边预留的空白高度
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    
    return 20;
}
//每个分组下边预留的空白高度
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (section==2) {
        return 40;
    }
    return 20;
}
//每一个分组下对应的tableview 高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0) {
        return 80;
    }
    return 40;
}

//设置每行对应的cell(展示的内容)
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifer=@"cell";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:identifer];
    if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifer];
    }
    
    if (indexPath.section==0) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"userinfo"];
        
        UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(12, 0, 80, 80)];
        imageView.image=[UIImage imageNamed:@"usericon.png"];
        [cell.contentView addSubview:imageView];
        
        UILabel *nameLabel=[[UILabel alloc]initWithFrame:CGRectMake(100, 0, 60, 80)];
        nameLabel.text=@"李晨";
        [cell.contentView addSubview:nameLabel];
    }else if (indexPath.section==1) {
        cell.textLabel.text=[dataSource objectAtIndex:indexPath.row];
    }else{
        cell.textLabel.text=@"退出登陆";
        cell.textLabel.textAlignment=NSTextAlignmentCenter;
    }
    return cell;
}

到此为止基本实现了整个界面




如果有问题可加qq讨论

苹果开发群 :414319235  欢迎加入


UIViewController
UITableViewDataSource,UITableViewDelegate

iOS 使用tableView实现 个人中心列表

标签:uitableview   个人中心   列表   微信   界面   

原文地址:http://blog.csdn.net/lwjok2007/article/details/46532161

(0)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!