【问题标题】:Conditional Segue from UITableView to DetailView based on object state基于对象状态的从 UITableView 到 DetailView 的条件 Segue
【发布时间】:2012-03-27 06:48:29
【问题描述】:

我已经设置了我的钻取表的 Xcode 故事板,以分支到两个详细视图。

我希望它根据我在表格视图中点击的预算对象的状态切换到任何一个。如果预算对象尚未初始化,我想继续初始化视图。如果它已被初始化,我希望它继续到详细视图。

到目前为止,这就是我所拥有的......

- (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];
    }
}

当然,这只会使其转到详细视图。我希望它在案例为budget.initialized = false 时使用“initializeBudget”segue 如何实现 performSegue:withIdentifier: 方法来执行此操作?

【问题讨论】:

    标签: objective-c ios xcode cocoa-touch uistoryboardsegue


    【解决方案1】:

    你需要根据你的情况触发performSegueWithIdentifier方法。

    类似:

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

    【讨论】:

    • 通过从您当前点击以触发它的对象中移除转场并让转场从视图控制器中移除来执行此操作。然后使用由原始对象上的操作触发的自定义函数。
    猜你喜欢
    • 2021-03-15
    • 1970-01-01
    • 2013-08-17
    • 2020-01-12
    • 1970-01-01
    • 2018-07-10
    • 2012-01-22
    • 1970-01-01
    • 2019-07-11
    相关资源
    最近更新 更多