如何使用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(Jake's Blog on 博客园)
出处:http://procoder.cnblogs.com
本作品由Jake Lin创作,采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。 任何转载必须保留完整文章,在显要地方显示署名以及原文链接。如您有任何疑问或者授权方面的协商,请给我留言。
出处:http://procoder.cnblogs.com
本作品由Jake Lin创作,采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。 任何转载必须保留完整文章,在显要地方显示署名以及原文链接。如您有任何疑问或者授权方面的协商,请给我留言。