如何使用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;
}

 

posted @ 2013-01-01 18:36  Jake Lin  阅读(1609)  评论(0)    收藏  举报
编辑推荐:
· 复杂业务系统线上问题排查过程
· 通过抓包,深入揭秘MCP协议底层通信
· 记一次.NET MAUI项目中绑定Android库实现硬件控制的开发经历
· 糊涂啊!这个需求居然没想到用时间轮来解决
· 浅谈为什么我讨厌分布式事务
阅读排行:
· 为大模型 MCP Code Interpreter 而生:C# Runner 开源发布
· 面试时该如何做好自我介绍呢?附带介绍样板示例!!!
· JavaScript 编年史:探索前端界巨变的幕后推手
· 复杂业务系统线上问题排查过程
· 独立开发:高效集成大模型,看这篇就够了
点击右上角即可分享
微信分享提示