【发布时间】:2013-12-27 16:23:16
【问题描述】:
我有问题。我创建了一个表格视图,其中列出了学生。通过单击相应的学生,会出现相应的详细信息视图。现在我在我的项目中实现了一个带有搜索结果的搜索栏,但是每次我使用搜索栏时,都会显示一个空的详细视图(没有任何机会选择正确的搜索结果)我真的不知道为什么。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Student Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
Student *student = nil;
if (tableView == self.searchDisplayController.searchResultsTableView)
{student = [self.searchResults objectAtIndex:indexPath.row];
NSString *fullname = [NSString stringWithFormat:@"%@ %@ (%@)", student.vorname, student.name, student.hatBetrGrund.name];
cell.textLabel.text = fullname;
[self performSegueWithIdentifier:@"Detail Student Seque" sender:student.name]; // if search results are found
}
else
{
student =[self.fetchedResultsController objectAtIndexPath:indexPath];
NSString *fullname = [NSString stringWithFormat:@"%@ %@", student.vorname, student.name];
cell.textLabel.text = fullname;
cell.detailTextLabel.text = student.hatBetrGrund.name;
}
return cell;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"Add Student Segue"])
{
AddStudent *addStudent = segue.destinationViewController;
addStudent.delegate = self;
addStudent.managedObjectContext = self.managedObjectContext;
}
else if ([segue.identifier isEqualToString:@"Detail Student Seque"])
{
DetailStudent *detailStudent = segue.destinationViewController;
detailStudent.delegate = self;
detailStudent.managedObjectContext = self.managedObjectContext;
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
self.selectedStudent = [self.fetchedResultsController objectAtIndexPath:indexPath];
detailStudent.student = self.selectedStudent;
}
else {
NSLog(@"wow, such Fail!");
}
}
【问题讨论】:
-
看起来和this one的问题一样。
-
@Mundi 对。马文,坚持一个答案,因为以下看起来像上一个。
标签: uitableview search core-data