is it possible to segue from a UITableViewCell on a UIView to another view

后端 未结 3 1807
挽巷
挽巷 2020-12-10 08:07

Xcode 4.6.1 iOS 6 using storyboards

My problem is this

I have a UITableView with dynamic prototype cells on a UIView in a UIViewController (that is itself e

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-10 08:49

    performSegueWithIdentifier: is a method of the UIViewController class. You cannot call it on a UITableView instance. Make your view controller implement the UITableViewDelegate protocol and set it as the delegate for the UITableView.

    Another option is that you don't use segues. In the same delegate method do:

    OtherViewController ov = [[OtherViewController alloc] init<>];
    // Or in case of storyboard:
    OtherViewController ov = [self.storyboard instantiateViewControllerWithIdentifier:@"ovidentifier"];
    
    // push view controller
    [self.navigationController pushViewController:ov animated:YES];
    

    If the delegate object is different from the view controller, then the easiest solution is to add a weak property to the delegate's class that keeps a reference to the viewController, like this:

    @property (weak) UIViewController *viewController;
    

    and set it up in the viewDidLoad of the viewController

    - (void) viewDidLoad {
        self.tableView1.viewController = self;
    }
    

    Make sure that the tableView1 property is declared like this:

    @property (IBACTION) (weak) SpecialTableView *tableView1;
    

    Sometimes using the storyboard is more painful than writing the code yourself.

提交回复
热议问题