Objective c 单元已创建,但未显示在UITableView中
这是我的第一个问题 我的UITableView不会显示创建的所有单元格。有什么问题吗 应用程序启动后,它会从服务器下载数据,并使用UITableView显示数据。当我滚动UITableView时,我的应用程序会下载更多数据,比如Twitter应用程序。一切都很好 但我也有一个UISearchBar。有个问题。当搜索栏处于活动状态时,所有内容都以相同的方式工作,例如,当我键入时,它下载第一部分数据,当我滚动时,它下载另一部分数据,但UITableView仅显示第一部分数据 但是CellForRowatineXpath中的NSLog告诉我,所有的单元格都创建得很好。我不知道该怎么办 对不起,我的英语不太好 此外,numberOfRowsInSection返回正确的值,例如3,而UITableView中仅显示1个单元格。当然,我的数组包含我需要显示的所有数据Objective c 单元已创建,但未显示在UITableView中,objective-c,xcode,uitableview,uisearchbar,Objective C,Xcode,Uitableview,Uisearchbar,这是我的第一个问题 我的UITableView不会显示创建的所有单元格。有什么问题吗 应用程序启动后,它会从服务器下载数据,并使用UITableView显示数据。当我滚动UITableView时,我的应用程序会下载更多数据,比如Twitter应用程序。一切都很好 但我也有一个UISearchBar。有个问题。当搜索栏处于活动状态时,所有内容都以相同的方式工作,例如,当我键入时,它下载第一部分数据,当我滚动时,它下载另一部分数据,但UITableView仅显示第一部分数据 但是CellForRow
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(searching == 0){ //if we aren't in search
NSLog(@"Total rows %d", ids.count);
return [ids count];
}
if(searching == 1){ //if we are in search
NSLog(@"Total rows %d", idsSearch.count);
return [idsSearch count];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
}
NSInteger row = [indexPath row];
if(searching == 0){
cell.textLabel.text = [names objectAtIndex:row];
NSLog(@"Cell with %@ created", [names objectAtIndex:row]);
}
if(searching == 1){
cell.textLabel.text = [namesSearch objectAtIndex:row];
NSLog(@"Cell with %@ created", [namesSearch objectAtIndex:row]); //tells me that ALL cells were created. But they aren't in UITableView.
}
return cell;
}
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
searchRequest = searchBar.text;
if([searchRequest isEqualToString:@""]){
searching = 0;
}
else{
searching = 1;
[idsSearch removeAllObjects];
[namesSearch removeAllObjects];
[self getArtistsStartFrom:0 withLimit:1]; //downloads new data (1 record in this example) with needed predicate (searchRequest) from server, then adds it to arrays and performs [self.tableView reloadData] at the end.
}
}
在testDidChange中,您是否尝试过执行[self.tableView重载数据]?