2012-07-17 66 views
1

我已经在Xcode中使用TableView和SearchDisplayController获得了主从应用程序。
在TableView中我有一个NSArray有10个条目。
如果我使用搜索栏,DetailView将正确显示我点击的条目。
但是,如果我不使用搜索栏并在条目上单击TableView,则每次DetailView都会显示TableView的第一个条目。
我能做些什么来解决它?DetailView仅显示Tableview的一个条目

MasterViewController.m:http://i.imgur.com/ZS1Oe.png

MasterViewController.h:

#import <UIKit/UIKit.h> 
@interface DPMasterViewController : UITableViewController 
@property (nonatomic, strong) IBOutlet UITableView *tableView; 
@end 

DetailViewController.m:http://i.imgur.com/AkVJ8.png

DetailViewController.h:

#import <UIKit/UIKit.h> 
@interface DPDetailViewController : UIViewController 
@property (strong, nonatomic) id detailItem; 
@property (strong, nonatomic) IBOutlet UILabel *detailDescriptionLabel; 
@end 

对不起,我使用的图片,但我认为这很简单呃给你检查。 :)
我希望你能帮助我!
如果有什么遗漏,请告诉我。

编辑:

在这种方法中的else后每次indexPath.row = 0。我不知道如何解决它:(

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 
if ([segue.identifier isEqualToString:@"showDetail"]) { 
    DPDetailViewController *destViewController = segue.destinationViewController; 

    NSIndexPath *indexPath = nil; 

    if ([self.searchDisplayController isActive]) { 
     indexPath = [self.searchDisplayController.searchResultsTableView indexPathForSelectedRow]; 
     destViewController.detailItem = [searchItemList objectAtIndex:indexPath.row]; 
    } else { 
     indexPath = [self.tableView indexPathForSelectedRow]; 
     destViewController.detailItem = [itemList objectAtIndex:indexPath.row]; 

    } 
    }  
} 
+0

你可以尝试描述你的问题好一点是详细视图中的问题或主视图? – 2012-07-17 19:52:36

+0

在我的MasterView中有一个带有SearchDisplayController和TableView的SearchBar。如果我在TableView中的条目(使用SearchBar)之后搜索并单击它,则View切换到DetailView并使用条目中的文本向我显示Label。这部分工作正常。但是当我不用SearchBar进行搜索时(我点击TableView中的一个条目),视图切换到DetailView,标签每次显示来自条目编号1的文本。 - >我点击条目2并在DetailView该标签显示条目1 – Schlodi 2012-07-17 21:09:32

回答

0

它看起来像你不执行didSelectRowAtIndexPath方法:当你点击的tableView是不是searchDisplayController的一部分的细胞,所以要尽量改变你的tableView任何行动?方法

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    [self performSegueWithIdentifier:@"showDetail" sender:self]; 
} 
+0

谢谢你的回答,但现在应用程序崩溃,我得到这个错误: '2012-07-17 22:55:11.532 APP [449:f803]嵌套的推动动画可能导致损坏的导航bar 2012-07-17 22:55:11.914 APP [449:f803]完成意外状态下的导航转换。导航栏子视图树可能会损坏。 2012-07-17 22:55:11.923 APP [449:f803]对于。的开始/结束外观转换的不平衡调用。 – Schlodi 2012-07-17 20:56:13

+0

您是如何在Storyboard中与tableView联系起来的? – Sascha 2012-07-17 21:01:59

+0

将细胞推入细节。 ---标识符:showDetail ---风格:推 – Schlodi 2012-07-17 21:12:58

相关问题