Getting title of UIButton in event handler

前端 未结 4 1635
囚心锁ツ
囚心锁ツ 2020-12-29 04:02

I create a button and set title as \"Click here\". When I press that button I want to get that button title and log it. Here\'s my code, where am I going wrong?



        
4条回答
  •  独厮守ぢ
    2020-12-29 04:40

    -(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 {       
    
         NSLog(@"The title is %@ ", [mybutton titleForState:UIControlStateNormal]);
    
    }
    

提交回复
热议问题