简体   繁体   中英

UIButton Action Not Called

I have a UIButton that I'm adding dynamically using content parsed from an XML file (it's also getting cached).

The first time I run the app, the button's action isn't getting called - but its image and everything else loads just fine. The second time I run the app, the button works.

Any clue on why the button's action doesn't get called the first time I run the app?

- (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];
                }
       }];
}

The issue was that a UIView was covering up the button below it. Because the view was transparent, I didn't realize it was covering anything up.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM