gpt4 book ai didi

ios - SWRevealViewController 无法识别 destinationViewController 的扇区

转载 作者:行者123 更新时间:2023-11-29 01:43:10 24 4
gpt4 key购买 nike

我正在使用 John Lluch 的 SWRevealViewController这很好用,除了我不知道如何在目标 View Controller 中设置选择器,就像我在其他 UIViewController 的 segues 中所做的那样。

有没有人遇到过这个问题?

这是我的代码:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

// Set the title of navigation bar by using the menu items
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
UINavigationController *destViewController = (UINavigationController*)segue.destinationViewController;
if ([segue.identifier isEqualToString:@"goalSegue"]) {

if ([segue.destinationViewController respondsToSelector:@selector(setTitleForViewController:)]) {
// use performSelector:withObject: to send without compiler checking
// (which is acceptable here because we used introspection to be sure this is okay)

NSString * titleText = @"Athlete Goals";

[segue.destinationViewController performSelector:@selector(setTitleForViewController:) withObject:titleText];
} else destViewController.title = [[menuItems objectAtIndex:indexPath.row] capitalizedString];

} else destViewController.title = [[menuItems objectAtIndex:indexPath.row] capitalizedString];

}

我在其他 View Controller 的 prepareForSegue 中使用了这段代码。选择器存在于目标 TableViewController 中,但 SWRevealViewController 忽略了 if 语句而不执行。

最佳答案

我认为问题在于您正试图在 UINavigationController 而不是选择器所在的实际 TableViewController 上运行选择器方法。请注意,destViewController 是一个 UINavigationController,其中包含您的 TableViewController

所以实际上,您可以尝试下面的代码,看看它是否有效(我已经在一个使用 SWRevealViewController 的示例项目中尝试过,它有效)

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

// Set the title of navigation bar by using the menu items
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
UINavigationController *destViewController = (UINavigationController*)segue.destinationViewController;
YourTableViewController *tableController = (YourTableViewController *)[destViewController childViewControllers].firstObject;
if ([segue.identifier isEqualToString:@"goalSegue"]) {

if ([tableController respondsToSelector:@selector(setTitleForViewController:)]) {
NSString * titleText = @"Athlete Goals";
[tableController performSelector:@selector(setTitleForViewController:) withObject:titleText];
} else destViewController.title = [[menuItems objectAtIndex:indexPath.row] capitalizedString];

} else destViewController.title = [[menuItems objectAtIndex:indexPath.row] capitalizedString];

}

据我所知,这可能不是 SWRevealViewController 的问题。

希望这对您有所帮助。

关于ios - SWRevealViewController 无法识别 destinationViewController 的扇区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32209142/

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