【问题标题】:UITableView doesn't call numberOfRowsInSection nor cellForRowAtIndexPathUITableView 不调用 numberOfRowsInSection 也不 cellForRowAtIndexPath
【发布时间】:2012-07-11 09:26:05
【问题描述】:

我不知道该怎么想...
我将主视图设置为包含UITableView。 (我也在该视图上使用 UIPickerView。)

我将它定义为符合协议:

UIPickerViewDelegate,
UIPickerViewDataSource,
UITableViewDataSource,
UITableViewDelegate

在我的观点h中公布了这两种方法:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;

在 m 中实现它们:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell=[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"] autorelease];
    cell.textLabel.text = [NSString stringWithFormat:@"Test %d",indexPath];
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 5;
}

我确实在我的viewDidLoad 中设置了代理:

searchTableView = [[UITableView alloc] init];
[searchTableView setFrame:CGRectMake(searchBar.frame.origin.x+10, 50, searchBar.frame.size.width-20, 300)];
searchTableView.delegate=self;

然而,从未调用过 numberOfRowsInSection 或 cellForRowAtIndexPath!

我做错了什么?

【问题讨论】:

  • 你设置数据源了吗?

标签: objective-c ios xcode


【解决方案1】:

设置数据源:

[searchTableView setDataSource:self];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-29
    • 1970-01-01
    • 1970-01-01
    • 2013-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多