how use @selector?

Discussion in 'iOS Programming' started by jalju, Jun 16, 2009.

  1. jalju macrumors newbie

    jalju

    Joined:
    Jun 16, 2009
    #1
    -(void) mymethod{
    UIButton *refreshbutton=[UIButton buttonWithType:UIButtonTypeCustom];
    [refreshbutton setFrame:CGRectMake(15.0f, 330.0f, 150.0f, 32.0f)];
    NSString *myvalue=[[NSString alloc]initWithString:mad:"YES IT IS OKy |"];
    [refreshbutton setTitle:mad:"Refresh" forState:UIControlStateNormal];
    [refreshbutton addTarget:self action:mad: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...
     
  2. dusker macrumors member

    Joined:
    May 31, 2009
    #2
    declare it in .h file so it'll be accessible by both methods
     
  3. BlackWolf macrumors regular

    Joined:
    Apr 9, 2009
    #3
    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.
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    What error are you getting?
     
  5. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #5
    Code:
    [refreshbutton addTarget:self action:@selector(showvalue:) forControlEvents:UIControlEventTouchUpInside];
     

Share This Page