【问题标题】:Conditional Destination View Controller from Sections in UITableView来自 UITableView 部分的条件目标视图控制器
【发布时间】:2013-07-24 22:14:55
【问题描述】:

TableView 控制器中的代码

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

    NSIndexPath *ip = [self.tableView indexPathForSelectedRow];

    if (ip.section == 0) {
        NSDictionary *currentBill = [[_response objectForKey:@"facturas_pendientes"] objectAtIndex:ip.row];
        DkBPaymentViewController *pvc = [[DkBPaymentViewController alloc] init];
        pvc = (DkBPaymentViewController *) segue.destinationViewController;
        pvc.setUp = currentBill;
    }
    else if(ip.section == 1){
        DkBBillsFileTableViewController *ftvc = segue.destinationViewController;
        ftvc.filesList = [[[_response objectForKey:@"facturas_pagadas"] objectAtIndex:ip.row] objectForKey:@"archivos_facturas"];
    }

}

错误

-[DkBBillsFileTableViewController setSetUp:]: unrecognized selector sent to instance 0x85a3b00
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DkBBillsFileTableViewController setSetUp:]: unrecognized selector sent to instance 0x85a3b00'

根据表格部分的部分(第 1 部分支付/第 2 部分已支付),您如何做或最好的方法是有条件地切换到不同的视图控制器?

详情

DkbPaymentViewController 有它自己的 xib,因为我无法让原型单元格指向两个不同的单元格

DkBBillsFileTableViewController 是我声明的原始 segue

在此先感谢您,我相信在 tableview 中找到一个好的条件 segue 方法将使所有人受益。

【问题讨论】:

  • 为什么没有 2 个单元格和 2 个 segues,指向 2 个不同的视图控制器?
  • 谢谢@wain,如果您添加您的答案,我很乐意接受。

标签: ios uitableview ios6 uistoryboardsegue


【解决方案1】:

您可以以编程方式进行。在情节提要中,从视图控制器(而不是单元格)中绘制两个 segue。然后在didSelectRowAtIndexPath,做这样的事情:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        [self performSegueWithIdentifier:@"SegueForSection1" sender:indexPath];
    } else if (indexPath.section == 1) {
        [self performSegueWithIdentifier:@"SegueForSection2" sender:indexPath];
    }
}

【讨论】:

  • 感谢您的回答,如果我的情况不同,我相信这会奏效!
  • 这正是我想要的!一开始我不小心让它为我自动完成didDeselectRowAtIndexPath,所以要小心
【解决方案2】:

您应该设置 2 个不同的单元格,每个单元格都链接到不同的 segue(因此它们具有不同的标识符),并且每个单元格都指向不同的视图控制器。这将使您的代码变得微不足道,防止类之间的混淆并按预期使用 segue。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多