Tôi hiện đang sử dụng SWRevealViewController cho trình đơn thanh bên trong ứng dụng của mình. Khi tôi nhấp vào một trong các tùy chọn, trình điều khiển chế độ xem đích không có nút 'quay lại' vì nó không đến từ trình điều khiển chế độ xem thích hợp (ví dụ: trang để quay lại).Nút quay lại tùy chỉnh nhanh và điểm đến
Vì vậy, tôi muốn tạo thủ công nút quay lại trên bộ điều khiển chế độ xem đích sẽ quay lại bộ điều khiển chế độ xem nhà.
tôi luôn nhìn vào mã ở đây: How do I manually set the "Back" destination in iOS apps
Nhưng tôi đang đấu tranh để thực hiện điều này trong Swift (một lỗi sau khi khác!). Bất kỳ giúp đỡ? Cảm ơn!
EDIT
Tôi đã thử những gợi ý dưới đây, nhưng nút quay lại chỉ không xuất hiện. Điều này có thể có cái gì đó với thực tế tôi có thanh điều hướng ẩn trong các chế độ xem khác và thực hiện các thao tác sau trên chế độ xem đích:
override func viewDidLoad() {
super.viewDidLoad()
navigationController.setNavigationBarHidden(false, animated:true)
var myBackButton:UIButton = UIButton.buttonWithType(UIButtonType.Custom) as UIButton
myBackButton.addTarget(self, action: "popToRoot:", forControlEvents: UIControlEvents.TouchUpInside)
var myCustomBackButtonItem:UIBarButtonItem = UIBarButtonItem(customView: myBackButton)
self.navigationItem.leftBarButtonItem = myCustomBackButtonItem
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func popToRoot(sender:UIBarButtonItem){
self.navigationController.popToRootViewControllerAnimated(true)
}
Không chắc chắn tại sao nút quay lại không hiển thị?
Sửa
Đây là prepareForSegue từ bộ điều khiển xem thanh bên tôi. Nếu có một cách để kiểm tra nhận dạng segue 'thử nghiệm' thì tôi có thể thiết lập nút quay lại từ đây?
- (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];
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];
};
}
}
bạn đã khắc phục chưa, tôi đã gặp vấn đề tương tự – marrioa