5

我有点卡在这个上,我有一个UIButton内部 a UIViewController,但由于某种原因UIButton没有响应。

_downloadButton = [[DownloadButtonViewController alloc] init];
_downloadButton.issue = _issue;
_downloadButton.view.frame = CGRectMake(self.descriptionLabel.frame.origin.x, self.descriptionLabel.frame.origin.y + self.descriptionLabel.frame.size.height + 20, 200, 27);
[self.view addSubview:_downloadButton.view];

UIButton *tmpButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
tmpButton.titleLabel.text = @"test";
tmpButton.frame = CGRectMake(_downloadButton.view.frame.origin.x, _downloadButton.view.frame.origin.y - 30, _downloadButton.view.frame.size.width, _downloadButton.view.frame.size.height);
[self.view addSubview:tmpButton];

为了查看是否没有任何东西与它重叠,我添加了UIButton一个稍微低一点的东西,即使我将它添加到相同的位置它仍然有效。

我的应用程序的结构是这样的

- UIViewController
    - UIScrollView
        - ThumbCover
            - UIImageView
            - DownloadButton --> NOT WORKING
            - UIButton --> WORKING
            - UILabel
        - ThumbCover
            - UIImageView
            - DownloadButton --> NOT WORKING
            - UIButton --> WORKING
            - UILabel
        - ThumbCover
            - UIImageView
            - DownloadButton --> NOT WORKING
            - UIButton --> WORKING
            - UILabel
        - ThumbCover
            - UIImageView
            - DownloadButton --> NOT WORKING
            - UIButton --> WORKING
            - UILabel

DownloadButton只是一个简单的UIButton,没有什么特别的。

4

6 回答 6

15

您已将 viewcontroller 视图的高度指定为 27

_downloadButton.view.frame = CGRectMake(self.descriptionLabel.frame.origin.x, self.descriptionLabel.frame.origin.y + self.descriptionLabel.frame.size.height + 20, 200, 27);

如果您的按钮框架在其父视图(视图控制器的视图)的框架之外,即上述框架,它不会响应您的触摸

于 2012-09-18T04:09:22.160 回答
0

你真的为按钮设置了一些目标吗?(问,因为在提供的代码中,我看不到!)否则,它当然不会响应。

于 2012-09-18T04:36:27.607 回答
0

我把你的代码,但改变了覆盖的两行,所以试试这个代码......

_downloadButton = [[DownloadButtonViewController alloc] init];
_downloadButton.issue = _issue;
_downloadButton.view.frame = CGRectMake(self.descriptionLabel.frame.origin.x, self.descriptionLabel.frame.origin.y + self.descriptionLabel.frame.size.height + 20, 200, 27);

UIButton *tmpButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
tmpButton.titleLabel.text = @"test";
tmpButton.frame = CGRectMake(_downloadButton.view.frame.origin.x, _downloadButton.view.frame.origin.y - 30, _downloadButton.view.frame.size.width, _downloadButton.view.frame.size.height);
[self.view addSubview:tmpButton];
[self.view addSubview:_downloadButton.view];

希望这可以帮助你...

:)

于 2012-09-18T05:32:44.290 回答
0

就我而言,我的动画过渡似乎尚未完成。我忘了completeTransition:Bool在我的方法的末尾 animateTransition:context放置我的视图控制器中的所有按钮禁用而不是userinteractionEnabled

于 2015-08-03T06:56:27.913 回答
-2

看着你这段代码

_downloadButton = [[DownloadButtonViewController alloc] init];

并不是我的意思是你的命名方式是错误的,但我怀疑你的 DownloadButtonViewController 是否是 UIButton。只是为了确保打开你的DownloadButtonViewController.h并检查你是否有这个

@interface DownloadButtonViewController : UIButton
于 2012-09-18T04:10:43.940 回答
-3
replace this line.. 

tmpButton.titleLabel.text = @"test";

作为

[tmpButton setTitle: @"test" forState:UIControlStateNormal];
于 2012-09-18T05:40:18.903 回答