请帮忙!这似乎很简单,但是,对不起,我'不得不'问,因为它不起作用。我有一个带有 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 方法。相反,有趣的是,主视图(子视图下方)中的组件被调用了!