【问题标题】:iOS App development : View visible but not activeiOS App开发:查看可见但不活动
【发布时间】:2012-08-14 12:27:53
【问题描述】:

请帮忙!这似乎很简单,但是,对不起,我“不得不”问,因为它不起作用。我有一个带有 UITableView 的主视图。在刷卡时,我添加了一个具有选择器和按钮的子视图。它工作正常:我滑动并且子视图出现在主视图的前面,但是当我单击选择器或按钮时,子视图中什么也没有发生;而是调用主视图(位于子视图下方)中的组件!我肯定会这么说,因为在主视图中,我在添加的子视图下方有一张图片(点击图片会打开一个新视图)。现在,当我在子视图中点击选择器时(图片在主视图下方),图片被点击并打开新视图!这怎么可能?

这是子视图(在 Interface Builder 中)

这是我的代码 sn-p:

在我的MainViewController.m中(viewCtrlrFilter是用户在主视图中滑动时添加的子视图):

....
self.viewCtrlrFilter = (ViewController_Filter *) [myStoryboard instantiateViewControllerWithIdentifier:kNameViewCtrlrFilter];
...
// This is called when the user pans/swipes
// This does work fine; the subview gets added & is visible
[self.viewCtrlrFilter initializeView];
[self.viewCtrlr.view setFrame:CGRectMake(310.0, 220.0, 243.0, 208.0)];
[self.view addSubview:self.viewCtrlrFilter.view];
...

来自 ViewController_Filter.h

...
// This implements the Picker Delegate & DataSource
// which I have wired to the picker in IB
@interface ViewController_FilterPhotographers : UIViewController <UIPickerViewDelegate, UIPickerViewDataSource>
...
// This is called when the button in the subview 
// (screenshot above) is pressed
// It's wired through the IB
-(IBAction) buttonPressed:(id) sender;
...

来自 ViewController_Filter.m

-(void) initializeView {

    self.myPicker.delegate = self;
    self.myPicker.dataSource = self;
    self.myPicker.showsSelectionIndicator = YES;

    CGRect rect = self.myPicker.frame;
    rect.origin = CGPointMake(0.0, 0.0);
    self.myPicker.frame = rect;
    self.myPicker.transform = CGAffineTransformMakeScale(0.625,0.625);
    [self.myPicker becomeFirstResponder];
}
...
-(IBAction) buttonPressed:(id) sender {
    NSLog(@"hi");
}
...
- (void)viewDidLoad
{
    [super viewDidLoad];
    [self initializeView];
}
...

当用户滑动时,确实会添加子视图(可以看到选择器和按钮),但是当我单击按钮时,IBAction 方法不会被调用。相反,有趣的是,主视图(子视图下方)中的组件被调用了!

【问题讨论】:

  • userIntactionEnable 为您的ViewController_Filter 吗?
  • 谢谢,Inder。是的,它为 IB 中的 ViewController_Filter.view、UIPicker、UIButton 启用。我现在又检查了一遍。所以,这不是问题。

标签: iphone ios cocoa-touch uiview uiviewcontroller


【解决方案1】:

现在可以了!看起来从代码和 IB 为选取器视图设置数据源和委托是一个问题。我从 IB 设置它并从代码中删除它。现在可以正常使用了!

【讨论】:

    猜你喜欢
    • 2015-10-22
    • 2015-11-19
    • 1970-01-01
    • 1970-01-01
    • 2020-01-31
    • 1970-01-01
    • 1970-01-01
    • 2019-01-30
    • 1970-01-01
    相关资源
    最近更新 更多