Storyboard Segue From View Controller to Itself

前端 未结 9 2175
无人及你
无人及你 2020-12-04 16:39

I am trying to make a mechanism to drill down a file / folder list. The idea is to show the same file list view controller every time the user selects a folder, and show a f

9条回答
  •  臣服心动
    2020-12-04 17:08

    In IOS 6, there is a cleaner solution than using a phantom button. You can still define the segue from the table cell to the view controller, and look at the sender to cancel the automatically triggered segue:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        //storyboards should use segues and override prepareForSegue instead
        //but here we need custom logic to determine which segue to use
        id item = [self.fetchedResultsController objectAtIndexPath:indexPath];
        if (item meets condition) {
            [self performSegueWithIdentifier:@"segue1" sender:self];
        } else {
            [self performSegueWithIdentifier:@"segue2" sender:self];
        }
    }
    
    - (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender {
        //ignore segue from cell since we we are calling manually in didSelectRowAtIndexPath
        return (sender == self);
    }
    

提交回复
热议问题