Getting title of UIButton in event handler

前端 未结 4 1632
囚心锁ツ
囚心锁ツ 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:42

    Your displayvalue: method should look something like this:

    -(void)displayvalue:(id)sender {       
        UIButton *resultButton = (UIButton *)sender;
        NSLog(@" The button's title is %@.",  resultButton.currentTitle);
    }
    

    (Please check out the documentation in XCode, it would have given you the right answer.)

提交回复
热议问题