0
我有一个UIButton,我使用从XML文件解析的内容动态添加(它也获取缓存)。UIButton Action Not Called
我第一次运行应用程序时,按钮的动作没有被调用 - 但它的图像和其他一切都加载得很好。第二次运行该应用程序时,该按钮有效。
任何线索为什么按钮的动作不会被称为第一次运行应用程序?
- (void)fetchHeader
{
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
// Initiate the request...
channel1 = [[FeedStore sharedStore] fetchFeaturedHeaderWithCompletion:
^(RSSChannel *obj, NSError *err) {
if(!err) {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
// Set our channel to the merged one
channel1 = obj;
RSSItem *d = [[channel1 items] objectAtIndex:0];
RSSItem *c = [[channel1 items] objectAtIndex:1];
NSString *param = [d photoURL]; // the URL from the XML
NSString *param1 = [c photoURL]; // the URL from the XML
featured1 = [[UIButton alloc] init];
[featured1 addTarget:self action:@selector(featuredButtonPress:) forControlEvents:UIControlEventTouchUpInside];
[featured1 setFrame:CGRectMake(18, 20, 123, 69)];
[featured1 setImageWithURL:[NSURL URLWithString:param] placeholderImage:[UIImage imageNamed:@"featuredheaderbg.png"]];
featured1.tag = 1;
[[self view] addSubview:featured1];
}
}];
}
当您在调试器中执行操作时,第一次和后续启动之间会发生什么不同吗? –
http://stackoverflow.com/questions/4908879/uibuttons-addtarget-not-called-after-touch-it?rq=1并且还将userEnteractionEnabled添加到TRUE –
检查没有其他视图覆盖按钮。即使按钮顶部的隐藏视图也会阻止它接收您的事件。 – Resh32