0
我有一个UIViewController
,我想要显示一个UIView
呈现为一个菜单。这个菜单上会有几个按钮。我想在我的应用程序的几个不同的地方重复使用这个菜单,所以我想我会创建一个名为ViewFactory
的类,该类有一个返回带有这些按钮的UIView
的方法。UIButtons无法以编程方式创建UIView
在我的ViewController
我打电话给这个方法,并得到返回UIView
并将其作为子视图添加它。
这工作得很好。我可以看到视图及其所有按钮,但是,按钮不响应任何触摸事件。不知道为什么这是这种情况,并好奇知道我做错了什么。
这里是我的ViewFactoryClass
代码:
- (UIView *) addCloseRow
{
// UIView container for everything else.
UIView *navRow = [[UIView alloc] initWithFrame:CGRectMake(0,225,350,45)];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.userInteractionEnabled = YES;
[navRow addSubview:button];
[button addTarget:self action:@selector(closeButtonTouchDownEvent) forControlEvents: UIControlEventTouchDown];
navRow.userInteractionEnabled = YES;
return navRow;
}
在我的主NavigationController
类这里是我如何打电话,并得到UIView
:
ViewFactory *factory = [[ViewFactory alloc] init];
[self.navigationController.navigationBar addSubview:[factory MainNavigationUIView]];
同样,UIView
显示出来,但按钮从不响应任何事情。
问题解决了Anoop!当更新我的方法传入对象时,我可以点击按钮。更新方法后,我回到我的NavigationViewController并传递类如下:'[self.navigationController.navigationBar addSubview:[工厂MainNavigationUIView:self]];'' – Flea 2013-04-29 18:17:17