admin 管理员组

文章数量: 1184232

tableview实现静态表格(xib版)

通过xib实现tableview的静态表格,效果如下

关联xib的属性

@interface MyTableViewController ()
@property (strong, nonatomic) IBOutlet UITableViewCell *userInfoCell;
//绿钻
@property (strong, nonatomic) IBOutlet UITableViewCell *greenDiamondCell;
//免流量服务
@property (strong, nonatomic) IBOutlet UITableViewCell *freeDataCell;
//定时关闭
@property (strong, nonatomic) IBOutlet UITableViewCell *ontimeCloseCell;
//退出登录
@property (strong, nonatomic) IBOutlet UITableViewCell *exitCell;@property (weak, nonatomic) IBOutlet UILabel *nicknameLabel;@end

代码实现

- (void)viewDidLoad {[super viewDidLoad];self.nicknameLabel.text = @"小苍";
}- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {return 4;
}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {if (section == 1) return 2;return 1;
}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {switch (indexPath.section) {case 0:return  self.userInfoCell;case 1:if (indexPath.row == 0) {return self.greenDiamondCell;}else {return self.freeDataCell;}case 2:return self.ontimeCloseCell;default:return self.exitCell;}
}-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {if (indexPath.section == 0) return 80;return 44;
}

自定义cell的xib如下图:

本文标签: tableview实现静态表格(xib版)