Selector keyword

-(void)clicketbutton{ 
    UIButton *mybutton = [UIButton buttonWithType:UIButtonTypeCustom];
    [mybutton setTitle:@"Click here" forState:UIControlStateNormal];
    [mybutton addTarget:self action:@selector(displayvalue:)forControlEvents:UIControlEventTouchUpInside];
}

-(void)displayvalue:(id)sender{
UIButton *resultebutton= [UIButton buttonWithType:UIButtonTypeCustom];

resultebutton=sender;// pls clear here.. my question here , it it possible or not. if possible how ? NSLog(@" The buttontitile is %@ ", [resultebutton.Title] // here also. }

      

In the above code, I am creating a button and setting the title as Click here

. When I click this button I want to print Click here

, I mean its name. For that, my code is here.

-4


a source to share


1 answer


iid is the sender, a pointer to the control calling your displayvalue method. You cast a pointer to an integer and print the integer result. I'm not sure exactly what you are trying to accomplish, but the fastest way to get an integer from a button to a button action method is to store it in a property tag

.



If you go into detail about what you are working on, I could describe a better way to model in a Cocoa app. Also, a tip - be sure to fix the warnings in your code before trying to figure out why something isn't working! This id -> int assignment might make the compiler complain, for example.

+1


a source







All Articles