【发布时间】:2014-03-15 09:30:00
【问题描述】:
提前致谢。
我正在尝试创建一个包含名称、图片和数字的数组的应用程序。我已经用相应数组中的所有数据创建了表格视图;我已经让搜索栏工作并显示正确的搜索。我缺少的是在另一个视图控制器中显示搜索栏的结果。 (我已经使用表格视图进行了此操作:我选择了一个名称,然后它会打开另一个视图,然后显示图片和数字等,)我只是错过了同样的东西,但是当我进行搜索时。
这是我的代码。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *simpleTableIdentifier = @"DreamCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
if (tableView == self.tableView) {
cell.textLabel.text = [Names objectAtIndex:indexPath.row];
cell.imageView.image =[UIImage imageNamed:[Images objectAtIndex:indexPath.row]];
} else{
cell.textLabel.text = [searchResults objectAtIndex:indexPath.row];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if (self.searchDisplayController.isActive) {
[self performSegueWithIdentifier:@"ShowDreamsDetails" sender:self];
}
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
if ([segue.identifier isEqualToString:@"ShowDreamsDetails"]) {
NSString *object =nil;
// NSIndexPath *indexPath =nil;
if (self.searchDisplayController.isActive) {
indexPath =[[self.searchDisplayController searchResultsTableView] indexPathForSelectedRow];
object = [searchResults objectAtIndex:indexPath.row];
/* *Here is where I have the problem, If I leave it like thi,s it only shows the first row in my array; I needed to send the correct name and details to the other View Controller. */
DesciptionViewController *desViewController = segue.destinationViewController;
desViewController.PrincipalName = [Names objectAtIndex:indexPath.row ];
desViewController.PrincipalDescription = [Description objectAtIndex:indexPath.row];
desViewController.PrincipalNumber = [Numeros objectAtIndex:indexPath.row];
desViewController.Images1 = [UIImage imageNamed: [Images objectAtIndex: indexPath.row]];
} else {
DesciptionViewController *desViewController = segue.destinationViewController;
desViewController.PrincipalName = [Names objectAtIndex:indexPath.row];
desViewController.PrincipalDescription = [Description objectAtIndex:indexPath.row];
desViewController.PrincipalNumber = [Numeros objectAtIndex:indexPath.row];
desViewController.Images1 = [UIImage imageNamed: [Images objectAtIndex: indexPath.row]];
}
}
}
提前感谢任何人,如果这是一个重复的问题,我很抱歉;我试图四处寻找,但没有找到任何东西。
【问题讨论】:
标签: ios objective-c xcode uitableview searchbar