我有一個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