故事版xib --view上添加tableview

以前我们实现过纯代码版view上添加tableview
http://blog.youkuaiyun.com/lee727n/article/details/72582677
下面我们来看一下,如何通过故事版和xib实现 效果如下
这里写图片描述

获取数据以及实现方式和前面一片微博一样,不在重复,具体参考:
http://blog.youkuaiyun.com/lee727n/article/details/72584807

这里具体介绍一下拖拽上的操作,首先通过故事版,拖拽一个tableview到viewcontroller上
这里写图片描述

将tableview关联到viewcontroller上
这里写图片描述

接下来除了实现代码还要记住,需要设置一下delegate和datasource,如下图
这里写图片描述

除了上述几步操作,代码和参考地址微博一模一样:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.allLists.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    //复用方式二
    ListCell *listCell = [tableView dequeueReusableCellWithIdentifier:@"listcell" forIndexPath:indexPath];

    NewsList *newsList = self.allLists[indexPath.row];
    listCell.newsTitleLabel.text = newsList.title;
    listCell.newsCommentCountLabel.text = [NSString stringWithFormat:@"%ld", newsList.commentCount];
    listCell.newsImageView.image = [UIImage imageNamed:newsList.newsImage];

    return listCell;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值