故事板 – 设置代表
在故事板之前,我可以通过将插口拖到一个类来设置代表和数据源。 通过故事板,我不能将sockets拖到另一个视图控制器; 没有目的地可以回应。
如果我点击一个视图控制器对象,我可以在底部看到类的所有者,但只要我select包含sockets的其他视图控制器,旧的select不见了,所以我不能连接这两个。
这是苹果的方式说我们应该只有编程连接他们?
正确。 在prepareForSegue:sender:
方法中设置委托或其他数据。 这里是一个例子:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Check the segue identifier if ([segue.identifier isEqualToString:@"showDetail"]) { // Get a reference to your custom view controller CustomViewController *customViewController = segue.destinationViewController; // Set your custom view controller's delegate customViewController.delegate = self; } }
如果您的故事板segue目标视图控制器是一个UIViewController然后@Marco答案是正确的。 但是,如果你的目标视图控制器是一个UINavigationViewController,那么你必须从UINavigationViewController获取UIViewController:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Check the segue identifier if ([segue.identifier isEqualToString:@"chooseCategoryType"]) { // Get a reference of your custom view controller if your segue connection is an UIViewController // CustomViewController *customViewController = segue.destinationViewController; // Get a reference of your custom view controller from navigation view controller if your segue connection is an UINavigationViewController CustomViewController *customViewController = [[[segue destinationViewController] viewControllers] objectAtIndex:0]; // Set your custom view controller's delegate customViewController.delegate = self; } }
- Apple Push – didReceiveIncomingPushWithPayload未被调用 – 而是错误:发送消息失败到客户端
- 无法在具有@objc属性的协议中使用自定义类?
- 自定义Google Sign In在GIDSignInDelegate协议上抛出exception
- 如何在表视图cusomization过程中调用“willDisplayFooterView”方法?
- 两个视图控制器之间的快速代表没有segue
- didOutputSampleBuffer委托没有被调用
- 令人沮丧的UIWebView委托崩溃问题
- 2 UITableView在UIViewController互相影响
- 如何委托工作和委托工作stream程在Objective-C