0

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

这是子视图(在 Interface Builder 中)

在此处输入图像描述

这是我的代码片段:

在我的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 方法。相反,有趣的是,主视图(子视图下方)中的组件被调用了!

4

1 回答 1

0

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

于 2012-08-18T06:30:01.877 回答