PDA

View Full Version : how use @selector?




jalju
Jun 16, 2009, 05:58 AM
-(void) mymethod{
UIButton *refreshbutton=[UIButton buttonWithType:UIButtonTypeCustom];
[refreshbutton setFrame:CGRectMake(15.0f, 330.0f, 150.0f, 32.0f)];
NSString *myvalue=[[NSString alloc]initWithString:@"YES IT IS OKy |"];
[refreshbutton setTitle:@"Refresh" forState:UIControlStateNormal];
[refreshbutton addTarget:self action:@selector(showvalue: myvalue) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:refreshbutton];
}

-(void) showvalue:(id)sender{

// here how to displs the value of "myvalue" ? myvalue is define in mymethod . i mean first method..
}

pls rectify the error in this code...



dusker
Jun 16, 2009, 07:18 AM
declare it in .h file so it'll be accessible by both methods

BlackWolf
Jun 16, 2009, 10:10 AM
1) please use code-tags in this forum
2) I think spaces are not allowed in selectors. also, I can't imaginge
[[NSString alloc]init
is working without a space, but I havn't tried.

dejo
Jun 16, 2009, 10:12 AM
pls rectify the error in this code...
What error are you getting?

PhoneyDeveloper
Jun 16, 2009, 10:18 AM
[refreshbutton addTarget:self action:@selector(showvalue:) forControlEvents:UIControlEventTouchUpInside];