6

我有两个 TableViewControllers,中间有一个 segue。当用户点击第一个 TVC 中的单元格时,他们会看到第二个 TVC。segue 是模态的,有一个名为“segueToLocationDetails”的标识符,并与它一起传递一个对象。您可以或多或少地将第二个 TVC 视为“详细信息”页面。

我的代码在我上面描述的场景中完美运行。但是,一旦我将第二个 TVC 嵌入导航控制器,它就会中断。

例子。我让它完美地工作。然后我突出显示 IB 中的第二个 TVC,将鼠标悬停到 Product | 嵌入 | 导航控制器。现在第二个 TVC 在导航控制器中。然而,segue 仍然指向第二个 TVC。我删除了 segue 并将其从第一个 TVC 的单元格重新连接到导航控制器,并确保为 segue 提供一个标识符。再跑,它就坏了!错误如下...

2011-12-23 15:30:45.469 Project12[5219:11603]-[UINavigationController setDetailsObject:]:无法识别的选择器发送到实例 0x7b92ce0 2011-12-23 15:30:45.471 Project12[5219:11603] * 由于应用程序终止未捕获的异常'NSInvalidArgumentException',原因是: ' - [UINavigationController的setDetailsObject:]:无法识别的选择发送到实例0x7b92ce0' *第一掷调用堆栈:(0x16ea052 0x150ad0a 0x16ebced 0x1650f00 0x1650ce2 0x3933 0x703e1e 0x36f6d9 0x36f952 0xbf786d 0x16be966 0x16be407 0x16217c0 0x1620db4 0x1620ccb 0x14ec879 0x14ec93e 0x2dfa9b 0x2a98 0x29f5 0x1) 终止调用抛出异常当前语言:自动;目前客观-c

下面是一些代码来帮助解释:

AllLocations.h & AllLocations.m(这是主表)

AllLocations.h

@interface AllLocations : UITableViewController
{
    SQLiteDB *mySQLiteDB;
}
@property (nonatomic, strong) NSMutableArray *locationsArray;



AllLocations.m

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

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"segueToLocationDetails"]) 
    {
        NSIndexPath *selectedIndexPath = [self.tableView indexPathForSelectedRow];
        NSInteger rowNumber = selectedIndexPath.row;

        mySQLiteDB = (SQLiteDB *) [locationsArray objectAtIndex:rowNumber];

        DetailsTVC *detailsTVC = [segue destinationViewController];

        detailsTVC.detailsObject = mySQLiteDB;        
    }
}

DetailsTVC.h & DetailsTVC.m(这是详细的表格视图)

DetailsTVC.h

@interface DetailsTVC : UITableViewController

@property (nonatomic, strong) SQLiteDB *detailsObject;


DetailsTVC.m

@implementation SpotDetailsTVC

@synthesize spotDetailsObject;

注意:我省略了所有与问题不重要或不相关的代码。

同样:如果 segue 从 Originating TableVeiwController 转到另一个 TableViewController,这将非常有效。只有当我将第二个 TVC 嵌入到导航控制器中时,它才会中断。我需要知道如何使用图片中的导航控制器来实现它。提前致谢!

4

1 回答 1

11

DetailsTVC *detailsTVC = [segue destinationViewController];

那条线是不正确的。由于您的第二个 TVC 现在嵌入在导航控制器中,因此 [segue destinationViewController] 现在是 UINavigationController。这应该有效:

DetailsTVC *detailsTVC = [[segue destinationViewController] visibleViewController];

于 2011-12-23T21:12:20.690 回答