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