ios - Matching 2 NSString values between class methods -


i understand can't pass instance variables within class methods, no longer confused difference between two.

hence little stuck.

i have 2 class methods , can both take nsstring argument.

is there anyway can matched up? because 1 class method has string url needs opened in safari after button pressed , therefore @selector(openbrowser:) needs know url jwkobjectview01

please tell me there way this??

i have tried changing instance methods, app crashes when press button - trying working out:-)

thanks in advance. ps know start saying understand can't mix 2 classes - far know, maybe missing something?

//added code:

uiview class .h file

@interface jwkobjectview01 : uiview <uiwebviewdelegate> {     nsstring *string;     nsurl *url;      nsuserdefaults *defaults; }  + (jwkobjectview01 *)anyview:(uiview *)anyview                          title:(nsstring *)title                         weburl:(nsstring *)webstring;  + (void)openbrowser:(nsstring *)urlstring; 

.m file

+ (jwkobjectview01 *)anyview:(uiview *)anyview                        title:(nsstring *)title                       weburl:(nsstring *)webstring {     jwkobjectview01 *anotherview = [[jwkobjectview01 alloc] initwithframe:cgrectmake(0,0,320,200)];     anotherview.backgroundcolor = [uicolor yellowcolor];      [anyview addsubview:anotherview];      uibutton *button = [uibutton buttonwithtype:uibuttontyperoundedrect];     button.frame = cgrectmake(20, 20, 100, 100);      [button settitle:title forstate:uicontrolstatenormal];     [button addtarget:self action:@selector(openbrowser:) forcontrolevents:uicontroleventtouchupinside];      [anotherview addsubview:button];      return anotherview; }  + (void)openbrowser:(nsstring *)urlstring; {      //this stuck , need variable - weburl:(nsstring *)webstring -       nsurl *url = [nsurl urlwithstring:urlstring];      [[uiapplication sharedapplication] openurl:url]; } 

.m file view controller

-(void)viewdidload   {      [jwkobjectview01 anyview:self.view title:@"open" weburl:@"http://google.com"];   } 

use static variable url. initialize in initialize method (that not init method). can of course add method sets static varialbe's value.

a static varialbe, class variables in other languages, exists once @ runtime.

but no class variables. naming conflicts when name used other static variables in other classes too. therefore make youself familiar singleton pattern , consider using whenever there need static varialbe.

some people "abuse" application delegate object containter values of global character. may not "out of book" works fine , quite common. however, beleive far better off singleton.

all assumes related url carry same value @ time instances of jwkobjectview01.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -