2014-03-06 95 views
0
- (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

你應該在主線程 – codercat

+0

更新您的數據提供的崩潰日誌請 –

+0

你重裝tableview中的任何地方 – codercat

回答

0

,如果你在主線程

,如果你是UI主線程

   dispatch_async(dispatch_get_main_queue(), ^(void){ 
       [self.tableView reloadData] 
      }); 
0

刷新你的tableview更新通過您的代碼看這裏,你要配置單元更新數據甚至在分配之前。 由於您正在返回呼叫,因此您在下面的行後面編寫的代碼將保持不變。

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; 

} 
+0

解決了,非常感謝 – RILEY