Ryusuke Fuda's Tech Blog

Softweare Enginier about Web, iOS, Android.

iOS TableViewのセルをカスタム

■ まずはTableViewつくるところ
http://www.appcoda.com/uitableview-tutorial-storyboard-xcode5/
http://www.appcoda.com/enhance-your-simple-table-app-with-property-list/
http://tanihiro.hatenablog.com/entry/2013/11/19/234920

■ 次にカスタム
http://tanihiro.hatenablog.com/entry/2013/11/26/210456

■ まずTableViewの.mへカスタムセルのヘッダーファイルをimport

#import "CustomCell.h"

■ custom nibを使う宣言

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.tableView registerNib:[UINib nibWithNibName:@"CustomCell" bundle:nil] forCellReuseIdentifier:@"cell"];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    // Configure the cell...
    NSDictionary *articles = self.news[indexPath.row];
    cell.cellTitleLabel.text = articles[@"title"];
    cell.cellTagLabel.text = articles[@"tag"];
    cell.cellDateLabel.text = articles[@"date"];
    return cell;
}

■ 注意点
順番にやっていきビルドすると、セルの高さが変わらなかった。あれ、と思うとこれを忘れていた。

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 78;
}