【发布时间】:2012-09-13 16:55:57
【问题描述】:
我有一个自定义 UIView 用于显示弹出框(在 iPhone 上)。在弹出窗口中有一些 UIButton,我需要从 ViewController 的类(不是 UIView 的类,而是显示 UIView 的 View)中调用方法。
如何正确设置?
位于自定义 UIView 类中的 UIView 按钮代码:
UIButton *logoutButton = [UIButton buttonWithType:UIButtonTypeCustom];
[logoutButton setTitle:@"Logout" forState:UIControlStateNormal];
[logoutButton setFrame:CGRectMake(0, 0, content.frame.size.width, 44)];
[logoutButton addTarget:self.superview.superview action:@selector(logout) forControlEvents:UIControlEventTouchUpInside];
[logoutButton setBackgroundImage:redImage forState:UIControlStateNormal];
[logoutButton setBackgroundImage:redImageHighlight forState:UIControlStateHighlighted];
[logoutButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[content addSubview:logoutButton];
【问题讨论】:
-
视图不应负责非视图逻辑,例如呈现弹出框。您应该处理按钮的触摸事件和您的视图控制器并从那里呈现弹出窗口。
标签: ios uiview methods uibutton