SWRevealViewController

SWRevealViewController

我使用的是John Lluch的SWRevealViewController,效果很好,但我无法像在其他UIViewController的讨论中那样弄清楚如何在目标视图控制器中设置选择器。

还有其他人遇到过这个问题吗?

这是我的代码:

- (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];

}


我在其他视图控制器的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/

10-13 04:00