SWRevealViewController 无法识别 destinationViewController 的扇区
SWRevealViewController does not recognize sectors for destinationViewController
我正在使用 John Lluch 的 SWRevealViewController,效果很好,除了我不知道如何在目标视图控制器中设置选择器,就像我在其他 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];
}
我已经在其他视图控制器的 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
的问题。
希望这对您有所帮助。
我正在使用 John Lluch 的 SWRevealViewController,效果很好,除了我不知道如何在目标视图控制器中设置选择器,就像我在其他 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];
}
我已经在其他视图控制器的 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
的问题。
希望这对您有所帮助。