我在我用Swift编写的应用程序中实现了RESideMenu并且它的实现很完美,但是当我点击具有View选项名称的单元格时,我不能将选择移动到其他View(例如:if我点击Profile me error以及其他单元格。
这是我转换成swift的代码:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
println("did select row: \(indexPath.row)")
if (indexPath.row == selectedMenuItem) {
return
}
selectedMenuItem = indexPath.row
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main",bundle: nil)
var salViewController : UIViewController
//sideMenuViewController!.setContentViewController(salViewController, animated: true)
switch (indexPath.row){
case 0:
salViewController = mainStoryboard.instantiateViewControllerWithIdentifier("Home") as UIViewController
break
case 1:
salViewController = mainStoryboard.instantiateViewControllerWithIdentifier("Profilo") as UIViewController
break
default:
break
}
}
这就是obj-c:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
switch (indexPath.row) {
case 0:
[self.sideMenuViewController setContentViewController:[[UINavigationController alloc] initWithRootViewController:[[DEMOFirstViewController alloc] init]]
animated:YES];
[self.sideMenuViewController hideMenuViewController];
break;
case 1:
[self.sideMenuViewController setContentViewController:[[UINavigationController alloc] initWithRootViewController:[[DEMOSecondViewController alloc] init]]
animated:YES];
[self.sideMenuViewController hideMenuViewController];
break;
default:
break;
}
}
我该如何解决?我依靠你的专家。
答案 0 :(得分:0)
switch (indexPath.row) {
case 0 :
println("case 0")
self.sideMenuViewController.setContentViewController(UINavigationController(rootViewController: self.storyboard?.instantiateViewControllerWithIdentifier("firstViewController") as! UIViewController)
, animated: true)
self.sideMenuViewController.hideMenuViewController()
break
case 1 :
println("case 1")
self.sideMenuViewController.setContentViewController(UINavigationController(rootViewController: self.storyboard?.instantiateViewControllerWithIdentifier("secondViewController") as! UIViewController)
, animated: true)
self.sideMenuViewController.hideMenuViewController()
break
default:
break