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

后端 未结 3 1806
挽巷
挽巷 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:44

    My Solution

    I ended up using a delegation pattern

    I made a segue dragging from the my UIViewController - specifically dragging from the viewController icon (the orange circle with a white square in it - from the name bar thats under the view in the storyboard - although you could also drag from the sidebar ) to the view that i wanted to segue to.

    I needed to trigger this segue from a table view cell on a table view.

    TableView Bit

    So i declared a protocol in my tableview header file - which is called LocationTV.h - as follows

    @protocol LocationTVSegueProtocol 
    
    -(void) makeItSegue:(id)sender;
    
    @end
    

    Below that I declare a property to hold my delegate

    @property (nonatomic, strong) id makeSegueDelegate;
    

    To actually trigger the segue i called the makeItSegueMethod on my makeSequeDelegate in my didSelectRowAtIndexPath method

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
    
    switch (indexPath.section) {
            DLog(@"selected row %d",indexPath.row);
        case dLocation:
        {
            if(indexPath.row == 2){
    
                [_makeSegueDelegate makeItSegue:self];
    
            } else if (indexPath.row == 7){
    

    UIViewController Bit

    and set up my UIViewController (named MultiTableHoldingVC) as implementing that protocol

    @interface MultiTableHoldingView : UIViewController    
                                       {
    
    }
    

    Below that i declared the protocol method in the list of my classes methods (although i'm not sure that is necessary as the compiler should know about the method as the decalration of implementing a protocol is essentially a promise to implement this method)

    -(void) makeItSegue:(id)sender;
    

    And then over in the implementation file of my UIViewController i wrote the method which essentially just calls preformSegueWithIdentifier

    -(void) makeItSegue:(id)sender{ 
        [self performSegueWithIdentifier:@"ChooseCountryNow" 
                                  sender:sender];   
    }
    

    And to link it all together,as in the header file I had declared my instance of the tableView as follows

    @property (strong, nonatomic) IBOutlet LocationTV *dsLocationTV;
    

    I had to set that tables views delegate property to be self - which I did in my UIViewControllers -(void)ViewDidLoad method

    _dsLocationTV.makeSegueDelegate = self;
    

    It all seems a bit of a kludge calling a method to call a method and allprog suggestion is simpler (I cant for the life of me work out why it threw up errors for me) but this works just fine . Thanks to both allprog and danypata for their suggestions.

    Hope this is helpful to someone out there

提交回复
热议问题