【发布时间】:2012-05-10 11:27:31
【问题描述】:
我在其他帖子中搜索过,但找不到解决方案。
我有一个无法点击的 UIButton。当我点击时,它不会变暗。 问题不在于选择器方法。
谁能帮帮我?!代码如下:
- (void)drawRect:(CGRect)rect
{
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 436)];
UIView *detailsView = [[UIView alloc] init];
// I have other components here and after the UIButton
UIButton *btnOpenPDF = [UIButton buttonWithType:UIButtonTypeCustom];
[btnOpenPDF setBackgroundImage:[UIImage imageNamed:@"btnVisualizarPdf"] forState:UIControlStateNormal];
[btnOpenPDF setFrame:CGRectMake(35, totalHeight, 249, 30)];
btnOpenPDF.userInteractionEnabled = YES;
[btnOpenPDF addTarget:self action:@selector(openPdf:) forControlEvents:UIControlEventTouchDown];
[detailsView addSubview:btnOpenPDF];
[scroll addSubview:detailsView];
[self addSubview:scroll];
}
上面的代码在一个 UIView 里面,它是通过 UIViewController 通过方法 -loadView() 调用的。
下面是openPdf的方法:
- (IBAction)openPdf:(id)sender{
// Creates an instance of a UIWebView
UIWebView *aWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320,450)];
// Sets the scale of web content the first time it is displayed in a web view
aWebView.scalesPageToFit = YES;
[aWebView setDelegate:self];
//Create a URL object.
NSURL *urlString = [NSURL URLWithString:[NSString stringWithFormat:@"http://portalarp.com.br/portal/%@",[[[[[[[delegateFunctions products] objectAtIndex:[delegateFunctions selectedProductIndex]] objectForKey:@"ata"] objectForKey:@"nm_arquivo"] objectForKey:@"text"] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] stringByReplacingOccurrencesOfString:@"\t" withString:@""]]];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:urlString];
//load the URL into the web view.
[aWebView loadRequest:requestObj];
[self addSubview:aWebView];
[aWebView release];
}
【问题讨论】:
-
您确定事件“UIControlEventTouchDown”.. 还是您尝试像往常一样按下“UIControlEventTouchUpInside”??
-
它正在使用 UIControlEventTouchDown,因为我在另一篇文章中看到它对某人有用......但是,同时使用它们,它仍然不起作用。
-
“仍然不起作用”是什么意思..按钮没有突出显示或选择器根本没有调用?!
-
按钮没有高亮显示,所以选择器根本没有被调用...
-
ok 尝试将 detailView 的背景颜色更改为红色,并检查您的按钮是否完全在红色区域内。
标签: objective-c ios cocoa-touch uibutton