Conditional Segue from UITableView to DetailView based on object state

血红的双手。 提交于 2019-12-07 16:26:31

问题


I've set up the Xcode storyboard of my drill down table to branch out to two detail views.

I want it to segue to either one based on the status of the Budget object that I tapped in the table view. If the budget object has not been initialized, I want to to segue to the initializing view. If it has been initialized, I want it to segue to the detail view.

So far, this is what I have...

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    /*
     When a row is selected, the segue creates the detail view controller as the destination.
     Set the detail view controller's detail item to the item associated with the selected row.
     */

    if ([[segue identifier] isEqualToString:@"showDetailsOfBudget"]) 
    {

        NSIndexPath *indexPath = [self.budgetsTable indexPathForSelectedRow];
        BudgetDetailsViewController *detailsViewController = [segue destinationViewController];
        detailsViewController.budget = [self.budgetPlan.budgets objectAtIndex:indexPath.row];
    }
}

Of course, this only makes it segue to the detail view. I want it to use the "initializeBudget" segue for when the case is budget.initialized = false How do I implement a performSegue:withIdentifier: method to do this?


回答1:


You need to fire off the method performSegueWithIdentifier depending on your condition.

Something like:

if ([self.budgetPlan.budgets count] > 0) {
    [self performSegueWithIdentifier@"showDetailsOfBudget"];
} else {
    [self performSegueWithIdentifier@"createBudget"];
}


来源:https://stackoverflow.com/questions/9884619/conditional-segue-from-uitableview-to-detailview-based-on-object-state

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!