如何使用UITableView

简介:

使用UITableView,可以直接拖动Table View Controller,这样会生成一堆模板代码,往你们填就行了,但是有时候不能直接这样拉,例如已经有一个UIView(可能在Navigation View或者Tabbed View里面)想在上面添加Table View。下面是步骤。

 

1.先把Table View控件拉到UIView中。

2.做一个connection绑定,把这个Table View绑定到UIOutlet。确认h文件包含了@property,而m文件包含@synthesize。

3.把tableview的dataSource和delegate绑定(connections)到UIViewController上。

4.继承两个protocols

@interface  JLDividendsViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>

5.重写几个方法

- ( NSInteger )numberOfSectionsInTableView:(UITableView *)tableView
{
     return  1;
}
 
- ( NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:( NSInteger )section
{
     return  [ self .divisions count];
}
 
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:( NSIndexPath  *)indexPath
{
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@ "DivisionCell" ];
     
     JLDivision *division = [ self .divisions objectAtIndex:indexPath.row];
     
     cell.textLabel.text = division.divisionNumber;
     return  cell;
} 本文转自Jake Lin博客园博客,原文链接:http://www.cnblogs.com/procoder/archive/2013/01/01/How-to-use-UITableView.html,如需转载请自行联系原作者
相关文章
|
9月前
RxSwift+MVVM项目实战-多分组UITableView+RxDataSources+MJRefresh的使用
RxSwift+MVVM项目实战-多分组UITableView+RxDataSources+MJRefresh的使用
107 0
|
9月前
|
JSON HandyJSON Swift
RxSwift+MVVM项目实战-多分组TableView+MJRefresh+RxAlamofire+HandyJSON的使用
RxSwift+MVVM项目实战-多分组TableView+MJRefresh+RxAlamofire+HandyJSON的使用
247 0
|
iOS开发 容器
(五)UITableView的用法一
(五)UITableView的用法一
172 0
UITableView的创建
UITableView的创建
81 0
|
存储 iOS开发 搜索推荐