cocoa-touch - 如果按下UIButton Xcode

标签 cocoa-touch ios uibutton

是否可以使用if语句查看是否已按下按钮?

if(condition) {
  //Do something
}

作为条件必须做什么?

最佳答案

UIButton将调用一个方法,将其连接到Interface Builder或set to in code中。

如果您需要了解程序的某些部分,如果按下了按钮,则可以执行以下操作:

-(IBAction)buttonTapped:(UIButton *) sender
{
    self.buttonPressed = YES; //bool instance variable with property
}

-(void)someOtherMethod
{
    if(self.buttonPressed){
        //do what you want to do, if button pressed
    }
}

但是我认为,在语义级别上将UI和逻辑紧密耦合在一起并不是一个好主意。

关于cocoa-touch - 如果按下UIButton Xcode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5290345/

相关文章:

iphone - 何时正确释放对象

ios - 如何在 ios 中使用 google Analytics,而无需在所有库中扩展库 GAY Tracked ViewController

ios - 如何通过 Storyboard向 UIButton 添加 subview ?

ios - UIControlEventTouchDragExit 在距 UIButton 100 像素时触发

iphone - 覆盖 UITableView 上的滑动手势

iphone - quartz 2d/核心图形 : What is the right way to draw some text?

ios - 将 mergeChangesFromContextDidSaveNotification 触发 fetchedResultsController 的 objectsChanged : delegate methods?

iphone - 将图像从UIImagePickerController存储在iPhone中?

ios - 使用清晰的背景颜色使 UIButton 内容完全可点击

iphone - CGContextRotateCTM 没有旋转 UIButton