【发布时间】: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