objective c - segue.identifier coming up (null) -


i noobie trying figure why segue.identifier coming (null), before segue (prepareforsegue) , after segue (unwindtolist). doing wrong, or missing? i've set segue identifier correctly scenes involved (in segue attributes). (another member here kindly tried help, no avail.)

here code:

in addtodoitemviewcontroller.m (source unwind):

    - (void) prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender {     nslog(@"segue identifier sender: %@", segue.identifier);//comes (null)...??      self.todoitem = [[todoitem alloc] init];//this code works fine if not conditional in unwind scene     if (sender != self.donebutton) return;//this code works fine if not conditional in unwind scene     if (self.textfield.text.length > 0 ) {//this code works fine if not conditional in unwind scene         self.todoitem.itemname = self.textfield.text;//this code works fine if not conditional in unwind scene         self.todoitem.completed = no;//this code works fine if not conditional in unwind scene         self.todoitem.flag = 1;//this code works fine if not conditional in unwind scene     } } 

in todolistviewcontroller.m (destination unwind):

    - (ibaction)unwindtolist:(uistoryboardsegue *)segue {     todolistviewcontroller *source = [segue sourceviewcontroller];     nslog(@"segue from: %@", source);//no problem here... correct scene logged     nslog(@"segue identifier: %@", segue.identifier);//comes (null)...??     if ([segue.identifier isequaltostring:@"additemscene"]) {//condition false...??         if (source.todoitem.flag == 1) {         todoitem *item = source.todoitem;         if (item != nil) {             [self.todoitems addobject:item];             [self.tableview reloaddata];             }         }     }     if ([segue.identifier isequaltostring:@"(a different scene"]) {         //do else     } } 

here solution/workaround unwind part of problem:

let's have 2 view controller classes, topviewcontroller , modaldialogviewcontroller. , there 3 segues topviewcontroller modaldialogviewcontroller, created in storyboard.

in modaldialogviewcontroller.h create enumerated type:

typedef enum { md_aboutdialog, md_helloworlddialog, md_anotherdialog } md_dialogtype; 

then add property it:

@interface modaldialogviewcontroller : uiviewcontroller @property (nonatomic) el_dialogtype dialogtype; @end 

each of dialog types associated segue identifier entered in storyboard; make pound-defines them in modaldialogviewcontroller.h:

#define md_segueaboutdialogid       @"aboutdialogsegueid" #define md_seguehelloworlddialogid  @"helloworlddialogsegueid" #define md_segueanotherdialogid     @"anotherdialogsegueid" 

in topviewcontroller, have prepareforsegue , "unwind dialog" methods:

- (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender {     md_dialogtype dialogtype;      if ([segue.identifier isequaltostring:md_segueaboutdialogid]) {         dialogtype = md_aboutdialog;     }     else if ([segue.identifier isequaltostring:md_seguehelloworlddialogid]) {         dialogtype = md_helloworlddialog;     }     else if ([segue.identifier isequaltostring:md_segueanotherdialogid]) {         dialogtype = md_anotherdialog;     }     else         return; // shouldn't here      modaldialogviewcontroller *dialogcontroller = (modalviewcontroller *)segue.destinationviewcontroller;     dialogcontroller.dialogtype = dialogtype;     // whatever other setup need } 

meanwhile, when unwind:

- (ibaction)unwindfromdialogonok:(uistoryboardsegue *)segue {     modaldialogviewcontroller *dialogcontroller = (modalviewcontroller *)segue.sourceviewcontroller;      if (dialogcontroller.dialogtype == md_aboutdialog) {         //     }     else if (dialogcontroller.dialogtype == md_helloworlddialog) {         // else     }     else if (dialogcontroller.dialogtype == md_anotherdialog) {         // else entirely }  - (ibaction)unwindfromdialogoncancel:(uistoryboardsegue *)segue {     modalviewcontroller *dialogcontroller = (modalviewcontroller *)segue.sourceviewcontroller;      if (dialogcontroller.dialogtype == md_anotherdialog) {         // take action needed if canceled     } } 

of course, solution works if segue identifier non-null in prepareforsegue method. , there may reason our segues have null identifiers on unwind - , if solved, there no reason this. it's know have full access both controllers, can use properties pass information.

an addition if still can't non-null segue identifier in prepareforsegue have corresponding dialogtype property in topviewcontroller use set corresponding dialogtype in modaldialogviewcontroller, since have access both controllers.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -