i have home screen.
on button press. either fetch information server , store in object or create default information using class called "defaults.h/m"
- store variables. , "function.h/m"
manipulate default values , call methods.
how can pass data globally of future view controllers create. can access , use information.
here signin/notsignin code:
you can see call [function fetchinformation]. method checks if user has internet connection, proceeds set values in defaults class.
- (ibaction)signin:(uibutton *)sender { nsstring * username = self.usernametextfield.text; nsstring * password = self.passwordtextfield.text; if([function isinternetconnectionavailable]){ if([function login:username :password]){ [function fetchinformation]; } else{ uialertview * error = [function showerroralert:@"login" :@"username or password incorrect" : @"ok"]; [error show]; } } else{ uialertview * error = [function showerroralert:@"connection" :@"please connect internet" : @"ok"]; [error show]; } } - (ibaction)notsignedin:(uibutton *)sender { [function fetchinformation]; }
here fetchinformation method:
+(void)fetchinformation { //instantiate user defaults nsstring * information = @""; if([function isinternetconnectionavailable]){ //set learnfest data server using url request , json response information = [self getappinformation]; [self updatestoredlearnfestinformation:information]; } else{ //set default information information = [self getlocallearnfestinformation]; [self updatestoredlearnfestinformation:information]; } //[self debugout:@"information" :information]; [self decodeappinformation:information]; }
here updatestoredlearnfestinformation method:
+(void)updatestoredlearnfestinformation:(nsstring *)information { //set default learnfest information [self updatesaveddatawithstring:@"default" :@"default_information" :information]; }
and updatesaveddatawithstring method:
+(void)updatesaveddatawithstring:(nsstring *)file :(nsstring *)key :(nsstring * )value { [[nsuserdefaults standarduserdefaults] setvalue:value forkey:key]; [[nsuserdefaults standarduserdefaults] synchronize]; }
can offer solution?
thanks
update: i've added 3 methods use store default information app. please review , consider have done.
one of options use singleton object. can import module singleton declared required controllers , access properties , methods.
Comments
Post a Comment