gpt4 book ai didi

ios - 收到错误 "Unknown receiver coachMarksView; Did you mean WSCoachMarksView error?"

转载 作者:行者123 更新时间:2023-11-28 21:54:32 25 4
gpt4 key购买 nike

我目前正在实现 WSCoachMarksView在首次使用该应用程序时向用户介绍功能的框架。然而,我的 viewDidAppear 中的代码给出了以下错误: Unknown receiver 'coachMarksView';您是说“WSCoachMarksView”吗?

我不确定为什么会这样,因为我已经在 viewDidLoad 中实例化了 coachMarksView,所以它应该可以识别它。我错过了什么吗?

- (void)viewDidLoad
{
[super viewDidLoad];

// Setup coach marks
NSArray *coachMarks = @[
@{
@"rect": [NSValue valueWithCGRect:(CGRect){{50,168},{220,45}}],
@"caption": @"Just browsing? We'll only notify you periodically of new matches. Need it soon? We'll notify you more frequently, and match you with items that are closer to you."
},
];

WSCoachMarksView *coachMarksView = [[WSCoachMarksView alloc] initWithFrame:self.navigationController.view.bounds coachMarks:coachMarks];
[self.navigationController.view addSubview:coachMarksView];
coachMarksView.animationDuration = 0.5f;
coachMarksView.enableContinueLabel = YES;
[coachMarksView start];
}

- (void)viewDidAppear:(BOOL)animated
{

// Show coach marks
BOOL coachMarksShown = [[NSUserDefaults standardUserDefaults] boolForKey:@"WSCoachMarksShown"];
if (coachMarksShown == NO) {
// Don't show again
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"WSCoachMarksShown"];
[[NSUserDefaults standardUserDefaults] synchronize];

// Show coach marks
[coachMarksView start];

// Or show coach marks after a second delay
// [coachMarksView performSelector:@selector(start) withObject:nil afterDelay:1.0f];
}
}

最佳答案

您需要将 coachMarksView 设为一个属性,以便您可以访问同一实例。 coachMarksView 在 vi​​ewWillAppear: 中未定义,因为该范围不知道 viewDidLoad 中的范围。

要为 coachMarksView 创建属性,您需要在 viewController 中执行以下操作:

@interface UIViewController ()
@property (nonatomic, strong) WKCoachMarksView *coachMarksView;
@end

然后在viewDidLoad

- (void)viewDidLoad
{
self.coachMarksView = [[WSCoachMarksView alloc] initWithFrame:self.navigationController.bounds]];
}

现在只需使用 self.coachMarksView 即可访问该实例。

- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self.coachMarksView start];
}

这里是关于 Objective-C 中的 getter、setter 和属性的更多信息 http://rypress.com/tutorials/objective-c/properties.html

关于ios - 收到错误 "Unknown receiver coachMarksView; Did you mean WSCoachMarksView error?",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27048330/

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