我有一个UIView .xib文件。这是从故事板入口点UIViewController1作为子视图打开的。子视图有一个IBButton,当它按下时打开一个UIViewController2。这有可能吗?从子视图访问UIViewcontroller - iOS
回答
首先,创建一个从你的第一个视图控制器到你的第二个视图。我要命名它OpenViewController2
。我们将能够以编程方式调用该segue。
在你UIView
h文件,创建定义代表该视图的协议:
SomethingView.h:
@protocol SomethingViewDelegate <NSObject> {
- (void)importantThingHappened;
}
...
@interface SomethingView {
id<SomethingViewDelegate> delegate;
}
@property (nonatomic, strong) id<SomethingViewDelegate> delegate;
SomethingView.m:
@implementation
@synthesize delegate;
...
// The IBAction for the button in your view
- (IBAction)buttonClicked:(id)sender {
[delegate importantThingHappened];
}
MyViewController。米,您创建您的视图:
// Create view
UIView *myView = ...
myView.delegate = self;
在MyViewController后来:
// Implement the protocol. This function will be called when the button action
// inside of the UIView you created is pressed
- (void)importantThingHappened {
[self performSegueWithIdentifier:@"OpenViewController2" sender:self];
}
首先给你的IBButton一个独特的标签,并在UIViewController的viewDidLoad,
// add following line into viewDidLoad
[(UIButton*)[self.view viewWithTag:MY_UNIQUE_TAG_FOR_BUTTON] addTarget:self action:@selector(buttonPressed:) forControlEvent:UIControlEventTouchUpInside];
终于实现buttonPressed:任何你想要
-(void) buttonPressed:(UIButton*)aButton {
// do what you want to do.
}
我期待从一个视图控制器转到另一个按下UIView(子视图)上的按钮。那可能吗? – 2012-07-11 06:10:54
这个子视图是一个外部.xib文件 – 2012-07-11 06:13:36
是的,为什么不。你试一试 – 2012-07-11 06:16:55
- 1. 访问从子视图中的UIViewController方法
- 2. 从UITableViewController访问UIViewController?
- 3. 子视图从UIViewController中消失
- 4. CodeIgniter:从子文件夹访问视图
- 5. UIViewController中删除子视图
- 6. UIViewController和Autolayout子视图
- 7. UIViewController子视图不显示
- 8. 作为UIView中的子视图调用UIViewController视图的问题
- 9. 访问子视图在当前视图
- 10. 无法从UIViewController访问UIView
- 11. 访问的UIView从UIViewController中
- 12. Xcode 6访问UIAiewlication从UIViewController
- 13. 从随机类访问UIViewController
- 14. Angular 2.访问子视图
- 15. 访问子视图设置
- 16. Autolay iOS与单uiviewcontroller和多视图
- 17. iOS动画主UIViewController的视图高度
- 18. 在iOS 7上的UIViewController上禁用子视图用户交互
- 19. ios uiviewcontroller与collectionview子视图不显示单元格
- 20. 从ViewController访问Programatic视图?
- 21. 如何访问UITableViewRowAction的视图iOS 8
- 22. 在表视图中错误访问 - iOS
- 23. 如何在iOS视图中访问我的视图中的子类成员?
- 24. 访问父的UIViewController其子女UIViewControllers
- 25. 查看所有内容:UIWindow子视图VS UIViewController子视图
- 26. 从子视图中的UIButton调用UIViewController中的方法
- 27. 从视图模型访问视觉子元素wpf
- 28. UIViewController的视图
- 29. 从另一个UIViewController中移除视图控制器Swift iOS
- 30. SIGABRT访问到刚刚创建UIViewController的视图
有没有关于创建segue的示例?这是一个自定义的赛格吗? – 2012-07-11 05:50:08