我想知道如何在UITableView类上使用outlet,dataSource。我被卡住了,因为我不能查看表上的任何数据。有人知道是怎么回事吗?我看过其他网站,但他们的建议都不起作用。我尝试使用接口构建器应用程序将dataSource添加到UITableView类
发布于 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
发布于 2012-05-03 05:24:48
UITableViewDataSource和UITableViewDelegate通常在ViewController上设置。如果在UIViewController中使用UITableView,则需要在接口文件(*.h)中实现委托和数据源。
@interface YourViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>一旦声明了委托,您就可以实现3个方法来使表视图工作
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableViewhttps://stackoverflow.com/questions/10421802
复制相似问题