iOS 使用tableView實現 個人中心列表

來源:互聯網
上載者:User

標籤: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;//分割線    [email protected][@"我的分享",@"密碼管理",@"使用者協議",@"關於"];

實現一下幾個代理


#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 *[email protected]"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)];        [email protected]"李晨";        [cell.contentView addSubview:nameLabel];    }else if (indexPath.section==1) {        cell.textLabel.text=[dataSource objectAtIndex:indexPath.row];    }else{        [email protected]"退出登陸";        cell.textLabel.textAlignment=NSTextAlignmentCenter;    }    return cell;}

到此為止基本實現了整個介面




如果有問題可加qq討論

蘋果開發群 :414319235  歡迎加入


UIViewControllerUITableViewDataSource,UITableViewDelegate

iOS 使用tableView實現 個人中心列表

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.