tableview实现静态表格(xib版)

来源:互联网 发布:河源龙川广电网络 编辑:程序博客网 时间:2024/05/02 08:35

通过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如下图:
这里写图片描述

阅读全文
0 0