简体   繁体   中英

How can i add 2 segue on 1 action?

I have a tableview which is showing my array items. . I connected push style segue to detailviewcontroller screen with my storyboard but i dont want to all items go detailviewcontroller so i made a controller like that ;

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

if (sender == self.btnEkle) return;
if (sender == self.btnKrediKartlarim) return;

NSString *bankaAdi = [[mainList objectAtIndex:indexPath.row] objectForKey:@"BankaAdi"];

if (bankaAdi.length > 1) {

    KartDetay *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"KartDetay"];

    [self presentViewController:vc animated:YES completion:nil];

}

If bankaAdi.length > 1 my app should go to the KartDetay

if its not i mean else my app should go to the detailviewcontroller

these codes are working but there is an error in my compiler.

Unbalanced calls to begin/end appearance transitions for .

Sorry for my English i know i didn't describe myself clearly but please try to help me.

Thanks !

---UPDATED AREA----

First of all Thank you for answer.But it doesnt work or i couldnt do that.

1- I created 2 manuel different segues to my KartDetay("taksit" segue name) and my DetayEkran("detay" segue name)..

2-I used with these codes..

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

NSIndexPath *indexPath2 = [self.tableView indexPathForSelectedRow];
bankaAdi = [[mainList objectAtIndex:indexPath2.row] objectForKey:@"BankaAdi"];

if (bankaAdi.length > 1)
{
    [self performSegueWithIdentifier:@"taksit" sender:nil];
}

else
    {
    [self performSegueWithIdentifier:@"detay" sender:nil];
    }

}

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

    if ([segue.identifier isEqualToString:@"taksit"])
    {
    //if (sender == self.btnEkle) return;
    //if (sender == self.btnKrediKartlarim) return;

    KartDetay *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"KartDetay"];
    [self presentViewController:vc animated:YES completion:nil];

    }
 else
    {

        DetayEkran *detayEkran = [self.storyboard instantiateViewControllerWithIdentifier:@"DetayEkran"];
        [self presentViewController:detayEkran animated:YES completion:nil];
    }

When I run my app and tap my first cell which is bankaAdi>1.

App can go to KartDetay screen but my compiler says :

Unbalanced calls to begin/end appearance transitions for .

Thank you for answer again.

----ReUpdated Area --- problem is solved by Greg... Thank you for that Greg...

I made a huge mistake with these codes coz i call another DetayEkran *detayEkran = [self.storyboard instantiateViewControllerWithIdentifier:@"DetayEkran"]; [self presentViewController:detayEkran animated:YES completion:nil]; DetayEkran *detayEkran = [self.storyboard instantiateViewControllerWithIdentifier:@"DetayEkran"]; [self presentViewController:detayEkran animated:YES completion:nil];

in my prepareforsegue method. When i delete all instantiate codes in my prepareforsegue methods my app working fine...

So

Greg codes are working like a charm.. Thank you Greg !

The prepareForSegue:sender: method is invoked before opening the detail view controller. It is the place to prepare for the transition, not to present/push view controllers. The actual transition is done after the method has been invoked. Whether push or present is used, depends on the segue type in the storyboard.

Try using the tableView:didSelectRowAtIndexPath: method instead of the prepareForSegue:sender: method. This should solve your problem.

When the segue is called the prepareForSegue:segue method is called and it handles the transition, you shouldn't call presentViewController or push view controller manually.

The best way to do that is create two segue for KartDetay and detailviewcontroller with two different identifiers in storyboard.

And override didSelectRowAtIndexPath method, where you check your condition and run appropriate segue:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *bankaAdi = [[mainList objectAtIndex:indexPath.row] objectForKey:@"BankaAdi"];

    if (bankaAdi.length > 1) {
        [self performSegueWithIdentifier:@"YOUR1IDENTIFIER" sender:nil]
    }
    else
        [self performSegueWithIdentifier:@"YOUR2IDENTIFIER" sender:nil]

}

If you need to pass any parameters use prepareForSegue method:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if ([segue.identifier isEqualToString:@"YOUR1IDENTIFIER"]) {

        KartDetay *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"KartDetay"];

        [self presentViewController:vc animated:YES completion:nil];
    }
    else {
        //handle other view controller
    }
}

Just remember to replace segue identifiers with your one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM