objective c - SIGABRT When going back to MainViewController -


in app, when user presses button, want produce information topic on different view. e.g when user presses cat button, want new view come displaying title , description. however, when press dog goes same view changes information.

firstviewcontroller.h

#import "secondview.h"  @interface viewcontroller :uiviewcontroller  {     secondview *secondviewdata;     iboutlet uitextfield *textfield; }  @property (nonatomic, retain)secondview*secondviewdata;  -(ibaction)passdata:(id)sender;   @end 

firstviewcontroller.m

#import "viewcontroller.h" #import "secondview.h"  @implementation viewcontroller  @synthesize secondviewdata;  -(ibaction)passdata:(id)sender  {     secondview *second = [[secondview alloc] initwithnibname:nil bundle:nil];       self.secondviewdata = second;      secondviewdata.passedvalue = @"dog info";     [self presentmodalviewcontroller:second animated:yes]; }  @end 

secondviewcontroller.h

@interface secondview :uiviewcontroller  {     iboutlet uilabel *label;       nsstring *passedvalue; }  @property (nonatomic, retain)nsstring *passedvalue;  -(ibaction)back:(id)sender;  @end 

secondviewcontroller.m

#import "viewcontroller.h"  @implementation secondview  @synthesize passedvalue;  -(ibaction)back:(id)sender  {     viewcontroller *second = [[viewcontroller alloc] initwithnibname:nil bundle:nil];     [self presentmodalviewcontroller:second animated:yes]; }   - (void)viewdidload {     label.text = passedvalue;     [super viewdidload]; }   @end 

when execute code, comes sigabrt

if next view segued current view, can use: enter image description here

-(void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender {     if([segue.identifier isequaltostring:@"nextviewsegue"]){          nextviewcontroller *nextviewobj  = segue.destinationviewcontroller;         nextviewobj.somensstring = @"the string wanna pass";     }     else if ([segue.identifier isequaltostring:@"nextviewsegue2"]){         othernextviewcontroller *othernextviewobj  = segue.destinationviewcontroller;         othernextviewobj.somensstring = @"the string wanna pass";     } } 

---------------------------there way:---------------------------

you can use global variable pass parameters.

create class

.h

   @interface ixxxxxxglobal : nsobject     {         nsstring *globalstring;      }     @property (nonatomic,retain)nsstring *globalstring;     +(ixxxxxxglobal *)getinstance;     -(void) updatesetting;     @end 

.m

#import "ixxxxxxglobal.h"  @implementation ixxxxxxglobal  @synthesize globalstring;  static ixxxxxxglobal *instance = nil;   +(ixxxxxxglobal *)getinstance {     if(instance ==nil)     {         instance = [ixxxxxxglobal new];         // initial value preferences , settings.         // use <<preferences , settings>>       }     return instance; }  -(void)updatesetting {     //do update <<preferences , settings>>  }  @end 

every time use global variable, need this:

ixxxxxxglobal *ixxxxxxglobalobj=[ixxxxxxglobal getinstance]; ixxxxxxglobalobj.globalstring = @"your string"; nsstring *localstring = ixxxxxxglobalobj.globalstring; 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -