gpt4 book ai didi

iphone - 为什么我不能将我的 View Controller 用作属性?

转载 作者:行者123 更新时间:2023-11-28 22:45:20 25 4
gpt4 key购买 nike

出于某种原因,我在这里遇到错误

#import "OtherViewController.h"

@interface ViewController: UIViewController



@property (nonatomic, strong) OtherViewController *otherViewController;

这给了我一个错误,说“未知类型名称 OtherViewController” 为什么这会发生在我身上?这不是向其他 View Controller 发送消息的方式吗?如果是这样,您应该如何执行此操作?

最佳答案

从您发布的内容来看,您发布的内容没有任何问题。也就是说,您不需要为其他 VC 声明属性。您需要做的是在 OtherViewController 上声明一个公共(public)属性(如 NSString),然后您可以从 ViewController 类访问该属性。类似于(假设您使用的是 Storyboard):

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"MySegueID"]) {
OtherViewController *ovc = segue.destinationViewController;
ovc.myPublicNSStringProperty = @"Something";
}
}

关于iphone - 为什么我不能将我的 View Controller 用作属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13354349/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com