- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath**
{
static NSString *CellIdentifier = @"TableCell";
TableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];**
// Configure the cell...
int row = [indexPath row];
cell.TitleLabel.text = _Title[row];
cell.DescriptionLabel.text = _Description[row];
cell.FeeSchedule.text = _Fschedule[row];
cell.NonFS.text = _Nonfeeschedule[row];
cell.ThumbImage.image = [UIImage imageNamed:_Images[row]];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [medicalCodes objectAtIndex:indexPath.row];
return cell;
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
if (tableView == self.searchDisplayController.searchResultsTableView) {
cell.textLabel.text = [searchResults objectAtIndex:indexPath.row];
} else {
cell.textLabel.text = [medicalCodes objectAtIndex:indexPath.row];
}
return cell;
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if([[segue identifier] isEqualToString:@"ShowDetails"]) {
DetailViewController *detailviewcontroller = [segue destinationViewController];
NSIndexPath *myIndexPath = [self.tableView indexPathForSelectedRow];
int row = [myIndexPath row];
detailviewcontroller.DetailModal = @[_Title[row],_Description[row],_Fschedule[row],_Nonfeeschedule[row],_Images[row]];
}
}
`enter code here`- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
NSPredicate *resultPredicate = [NSPredicate
predicateWithFormat:@"SELF contains[cd] %@",
searchText];
searchResults = [medicalCodes filteredArrayUsingPredicate:resultPredicate];
}
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller
shouldReloadTableForSearchString:(NSString *)searchString
{
[self filterContentForSearchText:searchString
scope:[[self.searchDisplayController.searchBar scopeButtonTitles]
objectAtIndex:[self.searchDisplayController.searchBar
selectedScopeButtonIndex]]];
return YES;
}
我有一个问题,我正在尝试让我的搜索栏工作,但是此时此刻正在停止导致应用程序崩溃。我对任何更好地添加搜索栏的方法持开放态度。关于我能做什么的任何建议?任何帮助表示赞赏。
答案 0 :(得分:0)
如果您在主线程中更新数据
或
如果您使用UI主线程重新加载tableview更新
dispatch_async(dispatch_get_main_queue(), ^(void){
[self.tableView reloadData]
});
答案 1 :(得分:0)
在此处查看代码,即使在分配单元之前,您也正在配置单元。 你回复电话后,你在下一行之后写的代码将不受影响。
cell.textLabel.text = [medicalCodes objectAtIndex:indexPath.row];
return cell;
我不确定你要在-tableView中实现什么:cellForRowAtIndexPath:。但我建议你试试这个,
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"TableCell";
TableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier
forIndexPath:indexPath];
//you can also allocate your custom cell here and then configure it as your need.
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
// Configure the cell...
int row = [indexPath row];
cell.TitleLabel.text = _Title[row];
cell.DescriptionLabel.text = _Description[row];
cell.FeeSchedule.text = _Fschedule[row];
cell.NonFS.text = _Nonfeeschedule[row];
cell.ThumbImage.image = [UIImage imageNamed:_Images[row]];
cell.textLabel.text = medicalCodes[indexPath.row];
return cell;
}