UIButton delayed state change

后端 未结 5 1629
庸人自扰
庸人自扰 2020-12-31 03:31

I have a UIButton subview inside of a UITableViewCell.

When this button is touched, the user must hold the button for about a half second f

5条回答
  •  伪装坚强ぢ
    2020-12-31 04:03

    Edit: completely re-written following a misunderstanding of the question

    One way of thinking of a UIButton is as a shorthand way of setting up an area of the screen that can respond to various instantaneous touch events the response it makes is defined by UIControl's Target-Action system for delivering messages to other objects.

    UIControlEventTouchDown sounds like the one you need to respond to. It will be triggered as soon as someone touches inside your button - this is what the "Contact Info" button in SMS does.

    UIButton* myButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect]; // SEt up title, frame etc [myButton addTarget:self action:@selector(myButtonWasPressed) forControlEvents: UIControlEventTouchDown]; [myMainView addSubView:myButton];

    Will send a -(void)myButtonWasPressed message to the object this code runs from (ideally you view controller). In myButtonWasPressed you can then add a new view or take any action you like. The SMS app pushes a view controller to display the contact info using a navigation controller.

    If this still doesn't solve your problem, you're going to have to post some code in order to get more insight into what's going wrong.

提交回复
热议问题