UITableView不会调用numberOfRowsInSection也不cellForRowAtIndexPath

问题描述:

我不知道该怎么想......
我设置了我的主视图来包含UITableView。 (我使用一个UIPickerView以及在该视图)UITableView不会调用numberOfRowsInSection也不cellForRowAtIndexPath

我将它定义为符合协议:

UIPickerViewDelegate, 
UIPickerViewDataSource, 
UITableViewDataSource, 
UITableViewDelegate 

宣布,在我看来的小时两种方法:

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

实施他们在米:

- (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都被称为!

我在做什么错?

+0

你设置数据源? – tomidelucca 2012-07-11 01:26:47

设置数据源:

[searchTableView setDataSource:self]; 
+0

哦,谢谢!奇迹般有效!! – Ted 2012-07-11 01:36:22