1

在我的应用程序中,如果您点击某个区域,则会出现一个 UIPopoverController,其中包含在单击时执行某些任务的 UIButtons。UIButtons(称为 CableDisconnectButton)是 UIButton 的子类,因此我可以向它们添加两个附加属性。我还添加了 UILabels 来检查按钮

但是,按钮的背景图像是不可见的,或者直到我在某处点击屏幕时才会出现。UIlabels 显示得很好,但不是按钮。它可以是点击 UIPopoverController 或屏幕上的任何其他位置。一旦我第一次点击该按钮,按钮就会一直存在,直到应用程序关闭。所以,这只发生在启动之后,直到我第一次打开 UIPopover。在打开弹出框之前我点击了很多次。

按钮的功能和其他一切工作正常,但背景图像在第一次启动时被隐藏了,我不知道为什么。

以下是我创建按钮和 UILabel 的方法:

    //create custom button
CableDisconnectButton *removeConnectionButton = [CableDisconnectButton buttonWithType:UIButtonTypeCustom];
removeConnectionButton.frame = CGRectMake(x, y, 190, 80);
removeConnectionButton.backgroundColor = [UIColor clearColor];
[removeConnectionButton setBackgroundImage:[UIImage imageNamed:@"images/cable_disconnect_button.png"] forState:UIControlStateNormal];
[removeConnectionButton setBackgroundImage:[UIImage imageNamed:@"images/cable_disconnect_button_over.png"] forState:UIControlStateHighlighted];

//set input and output jacks to button properties
removeConnectionButton.inputJack = inputJack;
removeConnectionButton.outputJack = self.outputJackView;

//add action to button
[removeConnectionButton addTarget:self action:@selector(removeConnectionButtonTarget:) forControlEvents:UIControlEventTouchUpInside];

//create label for output
UILabel *outputConnectionLabel = [[UILabel alloc] initWithFrame:CGRectMake(x+18, y+5, 180, 22)];
outputConnectionLabel.backgroundColor = [UIColor clearColor];
outputConnectionLabel.textColor = [UIColor whiteColor];
outputConnectionLabel.text = self.outputJackView.jackDisplayName;
outputConnectionLabel.font = [UIFont systemFontOfSize:16];

//add subviews
[self addSubview:removeConnectionButton];
[self addSubview:outputConnectionLabel];

我尝试添加一个常规的、非自定义的 UIButton 并且它在没有点击的情况下出现。我怀疑它可能与子类 UIButton 有关,但我不确定为什么。添加到 UIButton 的额外属性是对功能至关重要且不能省略的字符串。

4

1 回答 1

0

在把我的头从桌子上敲了好几天之后,我遇到了“清理构建文件夹”选项。我已经多次清理项目,但不知道“清理构建文件夹”。要执行此操作,只需按住 Option 键,从菜单中单击 Product 并选择 Clean Build Folder。

因此,如果您的应用程序没有按照应有的方式运行并且根本没有意义,请尝试此操作。

于 2013-04-19T02:41:29.187 回答