【问题标题】:UIButton Action Not Called未调用 UIButton 操作
【发布时间】:2012-09-03 07:00:47
【问题描述】:

我有一个 UIButton,我使用从 XML 文件解析的内容动态添加它(它也被缓存)。

我第一次运行应用程序时,按钮的操作没有被调用 - 但它的图像和其他所有内容都可以正常加载。我第二次运行该应用程序时,该按钮有效。

关于为什么我第一次运行应用程序时按钮的操作没有被调用的任何线索?

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

【问题讨论】:

  • 当您在调试器中单步执行时,第一次和随后的启动之间会发生什么不同吗?
  • stackoverflow.com/questions/4908879/… 并将 userEnteractionEnabled 添加为 TRUE
  • 检查没有其他视图覆盖按钮。即使按钮顶部的隐藏视图也会阻止它接收您的事件。
  • 请在您的问题中分享函数 setNetworkActivityIndi​​catorVisible 的主体
  • Vimal,这是一个标准的 UIKit 函数 - 它向 UIStatusBar 添加了小微调器。

标签: iphone objective-c ios uibutton


【解决方案1】:

问题是 UIView 覆盖了它下面的按钮。因为视图是透明的,所以我没有意识到它覆盖了任何东西。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多