gpt4 book ai didi

objective-c - 从 TableViewController 到 NavController 中嵌入的第二个 TVC 的 performSegueWithIdentifier 不起作用

转载 作者:可可西里 更新时间:2023-11-01 03:40:18 26 4
gpt4 key购买 nike

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

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

例子。我让它工作得很好。然后我突出显示 IB 中的第二个 TVC,将鼠标移至 Product |嵌入 |导航 Controller 。现在第二个 TVC 在导航 Controller 中。然而,segue 仍然指向第二个 TVC。我删除了 segue 并将它从第一个 TVC 的单元格重新连接到导航 Controller ,并确保为 segue 提供一个标识符。再次运行,它坏了!错误如下...

2011-12-23 15:30:45.469 Project12[5219:11603] -[UINavigationController setDetailsObject:]: unrecognized selector sent to instance 0x7b92ce0 2011-12-23 15:30:45.471 Project12[5219:11603] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationController setDetailsObject:]: unrecognized selector sent to instance 0x7b92ce0' * First throw call stack: (0x16ea052 0x150ad0a 0x16ebced 0x1650f00 0x1650ce2 0x3933 0x703e1e 0x36f6d9 0x36f952 0xbf786d 0x16be966 0x16be407 0x16217c0 0x1620db4 0x1620ccb 0x14ec879 0x14ec93e 0x2dfa9b 0x2a98 0x29f5 0x1) terminate called throwing an exceptionCurrent language: auto; currently objective-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(这是详细的表格 View )

DetailsTVC.h

@interface DetailsTVC : UITableViewController

@property (nonatomic, strong) SQLiteDB *detailsObject;


DetailsTVC.m

@implementation SpotDetailsTVC

@synthesize spotDetailsObject;

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

再一次:如果 segue 从 Originating TableVeiwController 转到另一个 TableViewController,这将非常有效。只有当我将第二个 TVC 嵌入导航 Controller 时,它才会中断。我需要知道如何使用图片中的 Nav Controller 使其工作。提前致谢!

最佳答案

DetailsTVC *detailsTVC = [segue destinationViewController];

该行不正确。由于您的第二个 TVC 现在嵌入到导航 Controller 中,因此 [segue destinationViewController] 现在是 UINavigationController。这应该有效:

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

关于objective-c - 从 TableViewController 到 NavController 中嵌入的第二个 TVC 的 performSegueWithIdentifier 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8620639/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com