请帮忙!这似乎很简单,但是,对不起,我要问,因为它不起作用。我有一个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方法。相反,有趣的是,主视图中的组件(在子视图下方)被调用!
答案 0 :(得分:0)
现在有效!看起来像设置数据源&amp;从代码和代码中委托选择器视图IB是个问题。我从IB&amp;从代码中删除它。现在工作正常!