我在Objective-c中使用SWRevealController
在Objective-c 中我使用的代码如下:
- (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;
destViewController.title = [[menuItems objectAtIndex:indexPath.row] capitalizedString];
// Set the photo if it navigates to the PhotoView
if ([segue.identifier isEqualToString:@"mainVC"]) {
MainViewController *mainVC = (MainViewController*)segue.destinationViewController;
mainVC.isReveal = YES;
} else if ([segue.identifier isEqualToString:@"logOutVC"]) {
LogOutVC *logOutVC = (LogOutVC*)segue.destinationViewController;
} else if ([segue.identifier isEqualToString:@"groupsVC"]) {
GroupsVC *groupsVC = (GroupsVC*)segue.destinationViewController;
groupsVC.isReveal = YES;
} else if ([segue.identifier isEqualToString:@"setCustomRouteMapVC"]) {
SetCustomRouteMapVC *setCustomRouteMapVC = (SetCustomRouteMapVC*)segue.destinationViewController;
setCustomRouteMapVC.isReveal = YES;
}
if ( [segue isKindOfClass: [SWRevealViewControllerSegue class]] ) {
SWRevealViewControllerSegue *swSegue = (SWRevealViewControllerSegue*) segue;
swSegue.performBlock = ^(SWRevealViewControllerSegue* rvc_segue, UIViewController* svc, UIViewController* dvc) {
UINavigationController* navController = (UINavigationController*)self.revealViewController.frontViewController;
[navController setViewControllers: @[dvc] animated: NO ];
[self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
};
}
}
如何在Swift中使用相同的代码?
请你帮我解决这个问题。
答案 0 :(得分:0)
您能否看到以下代码我希望它对您有所帮助
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
switch indexPath.row
{
case 0:
let secondViewController = self.storyboard?.instantiateViewControllerWithIdentifier("viewController") as? ViewController
let navController = UINavigationController(rootViewController: secondViewController!)
navController.setViewControllers([secondViewController!], animated:true)
self.revealViewController().pushFrontViewController(navController, animated: true)
//self.revealViewController.pushFrontViewController:navController animated:YES];
break;
case 1:
let secondViewController = self.storyboard?.instantiateViewControllerWithIdentifier("viewController") as? ViewController
let navController = UINavigationController(rootViewController: secondViewController!)
navController.setViewControllers([secondViewController!], animated:true)
self.revealViewController().pushFrontViewController(navController, animated: true)
break;
default:
break;
}
}
而不是 prepareForSegue 你可以在UITableView中编写这段代码吗?选择方法
<强>(OR)强>
- (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
destViewController.title = menuItems.objectAtIndex(indexPath.row).capitalizedString()
// Set the photo if it navigates to the PhotoView
if (segue.identifier.isEqualToString("mainVC")) { MainViewController *mainVC = (MainViewController*)segue.destinationViewController
mainVC.isReveal = YES
}
else if (segue.identifier.isEqualToString("logOutVC")) {
LogOutVC *logOutVC = (LogOutVC*)segue.destinationViewController
}
else if (segue.identifier.isEqualToString("groupsVC")) {
GroupsVC *groupsVC = (GroupsVC*)segue.destinationViewController
groupsVC.isReveal = YES
}
else if (segue.identifier.isEqualToString("setCustomRouteMapVC")){
SetCustomRouteMapVC *setCustomRouteMapVC = (SetCustomRouteMapVC*)segue.destinationViewController
setCustomRouteMapVC.isReveal = YES
}
if ( segue.isKindOfClass(,SWRevealViewControllerSegue.class()) ){
SWRevealViewControllerSegue *swSegue = (SWRevealViewControllerSegue*) segue
swSegue.performBlock = ^(SWRevealViewControllerSegue* rvc_segue,UIViewController* svc,UIViewController* dvc) {
UINavigationController* navController = (UINavigationController*)self.revealViewController.frontViewController
navController.setViewControllers(,@[dvc],animated:,false,)
self.revealViewController.setFrontViewPosition(,FrontViewPositionLeft,animated:,true)
}
}
}