如何使用UITableView

本文详细介绍了如何在现有的UIView中集成UITableView,包括将TableView控件拖放到UIView、创建绑定连接、设置dataSource和delegate等步骤,并提供了具体的方法实现示例。

使用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,如需转载请自行联系原作者
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值