首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >dataSource插座

dataSource插座
EN

Stack Overflow用户
提问于 2012-05-03 05:11:41
回答 2查看 1.8K关注 0票数 2

我想知道如何在UITableView类上使用outlet,dataSource。我被卡住了,因为我不能查看表上的任何数据。有人知道是怎么回事吗?我看过其他网站,但他们的建议都不起作用。我尝试使用接口构建器应用程序将dataSource添加到UITableView类

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-05-03 05:20:23

UITableView的dataSource属性是您分配给tableView的委托...然后,当涉及到收集数据时,tableView调用指定的类。为了在tableView上显示数据,您需要实现UITableViewDataSource委托方法...

一个不错的起点是查看UITableView类参考:

http://developer.apple.com/library/ios/documentation/uikit/reference/UITableView_Class/Reference/Reference.html - UITableView类参考

http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UITableViewDelegate_Protocol/Reference/Reference.html - UITableViewDelegate协议类参考

http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDataSource_Protocol/Reference/Reference.html - UITableViewDataSource协议类参考

另外,请看下面的示例代码:

http://developer.apple.com/library/ios/ipad/#samplecode/TableViewSuite/Introduction/Intro.html

票数 2
EN

Stack Overflow用户

发布于 2012-05-03 05:24:48

UITableViewDataSource和UITableViewDelegate通常在ViewController上设置。如果在UIViewController中使用UITableView,则需要在接口文件(*.h)中实现委托和数据源。

代码语言:javascript
复制
@interface YourViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>

一旦声明了委托,您就可以实现3个方法来使表视图工作

代码语言:javascript
复制
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10421802

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档