1

Code in TableView Controller

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

}

Error

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

How can you do or what is the best way to conditional segue to different view controllers based on the section of the section of the table (Section 1 To pay / Section 2 Paid) ?

Details

DkbPaymentViewController has it's own xib given that I can't make the prototype cell to point to two different

DkBBillsFileTableViewController is the original segue that I declared

Thank you so much in advance, I believe that to find a good method of conditional segue in a tableview would benefit all.

4

2 回答 2

2

您可以以编程方式进行。在情节提要中,从视图控制器(而不是从单元格)中绘制两个 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];
    }
}
于 2013-07-24T22:43:47.663 回答
1

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

于 2013-07-25T00:15:54.060 回答