iOS TableView實現QQ好友名單(二)

來源:互聯網
上載者:User

標籤:ios   使用者資訊   tableview   qq   連絡人   

上節地址:http://blog.csdn.net/lwjok2007/article/details/46534123


上一節實現了簡單的好友名單,但是資訊不夠豐富,本節將好友的頭像,名稱,簽名等資訊全部顯示出來

此處我們需要自訂cell


建立一個類  繼承

UITableViewCell




添加所需屬性

#import <UIKit/UIKit.h>@interface UserTableViewCell : UITableViewCell@property (strong,nonatomic) UIImageView *headerphoto;//頭像@property (strong,nonatomic) UILabel *nameLabel;//暱稱@property (strong,nonatomic) UILabel *isOnLine;//是否線上@property (strong,nonatomic) UILabel *introductionLabel;//個性簽名,動態等@property (strong,nonatomic) UILabel *networkLabel;//網路狀態@end


重寫初始化方法 添加各屬性


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{    self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];    if (self) {        headerphoto=[[UIImageView alloc]initWithFrame:CGRectMake(10, 5, 50, 50)];        [self.contentView addSubview:headerphoto];                nameLabel=[[UILabel alloc]initWithFrame:CGRectMake(60, 5, 200, 25)];        nameLabel.backgroundColor=[UIColor clearColor];        nameLabel.font=[UIFont systemFontOfSize:16];        [self.contentView addSubview:nameLabel];                isOnLine=[[UILabel alloc]initWithFrame:CGRectMake(60, 40, 50, 5)];        isOnLine.font=[UIFont systemFontOfSize:10];        [self.contentView addSubview:isOnLine];                introductionLabel=[[UILabel alloc]initWithFrame:CGRectMake(120, 40, 180, 5)];        introductionLabel.font=[UIFont systemFontOfSize:10];        [self.contentView addSubview:introductionLabel];                networkLabel=[[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-50, 5, 50, 25)];        networkLabel.font=[UIFont systemFontOfSize:10];        [self.contentView addSubview:networkLabel];    }    return self;}



修改viewcontroller 中tablevew的delegate方法


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{        NSString *str=[titleArray objectAtIndex:indexPath.section];        NSArray *arr=[dataDic objectForKey:str];        static NSString *CellIdentifier = @"UserCell";        UserTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];    cell=nil;    if (cell == nil) {        cell = [[UserTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];                cell.selectionStyle = UITableViewCellSelectionStyleGray;    }        NSDictionary *dic=[arr objectAtIndex:indexPath.row];    cell.headerphoto.image=[UIImage imageNamed:[dic valueForKey:@"usericon"]];    cell.nameLabel.text=[dic valueForKey:@"name"];    [email protected]"[線上]";    [email protected]"無動態";    [email protected]"4G";        return cell;    }

將其中cell修改成自訂的cell 這樣就能按照自己想要的樣式去實現


先講到這裡,剩餘部分下節再講



如果有問題可加qq討論  

蘋果開發群 :414319235  歡迎加入  

 原始碼將在群共用發布


iOS TableView實現QQ好友名單(二)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.