以前我们实现过纯代码版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;
}