標籤: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好友名單(二)