Conditional Destination View Controller from Sections in UITableView

旧时模样 提交于 2019-12-08 06:30:06

问题


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.


回答1:


You should setup 2 different cells, each linked to different segues (so they have different identifiers), and each pointing to different view controllers. This will make your code trivial, prevent confusion between classes and use segues as they are intended.




回答2:


You can do it programatically. In the storyboard, draw your two segues from the view controller (rather than from the cell). Then in didSelectRowAtIndexPath, do something like this:

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


来源:https://stackoverflow.com/questions/17845732/conditional-destination-view-controller-from-sections-in-uitableview

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