在没有interfase的情况下将dataSource添加到tableView并显示它

时间:2012-08-30 15:13:50

标签: iphone objective-c uitableview

我有勇气:

@interface Box : CDVPlugin <UITableViewDataSource, UITableViewDelegate, UISearchDisplayDelegate>

现在在一个事件之后,我想用不同类型的数据显示tableView。 我创建了一个tableView并添加了它......正在工作

UITableView *tView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 150, 150)];
      [[self.webView superview] addSubview:tView];

如何连接它做一个dataSource?

我尝试添加:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

但它永远不会停在那里而且表总是空的。 如何将它与数据连接(NSMutableArray)?

1 个答案:

答案 0 :(得分:0)

你永远不会告诉表查看谁是dataSource

你可以这样做:

UITableView *tView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 150, 150)];
tView.dataSource = self; // or something else
tView.delegate = self; // or something else
[[self.webView superview] addSubview:tView];

DataSource用于创建单元格(cellForRowAtIndex:,numberOfRowsInSection:等) 委托是用于行动的,例如(didSelectRowAtIndexPath :)