ios 获取错误“Unknown receiver coachMarksView; Did you mean WSCoachMarksView error?”

taor4pac  于 12个月前  发布在  iOS
关注(0)|答案(3)|浏览(131)

我目前正在实现WSCoachMarksView框架,以便在第一次使用应用程序时向用户介绍功能。然而,我的viewDidAppear中的代码给了我以下错误:Unknown receiver 'coachMarksView'; Did you mean '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];
    }   
}

字符串

3j86kqsm

3j86kqsm1#

您需要将coachMarksView设置为一个属性,这样您就可以访问同一个示例。coachMarksView在viewWillAppear中是未定义的:因为该作用域不知道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];
}


以下是有关XNUMBER-C http://rypress.com/tutorials/objective-c/properties.html中的getter、setter和属性的更多信息

o4tp2gmn

o4tp2gmn2#

您已经将coachMarksView声明为viewDidLoad内部的局部变量。“Local”意味着它只在您声明的位置可见。
尝试将其改为类的属性,以便对象可以从其所有方法访问它。(使用self.coachMarksView。)

gcuhipw9

gcuhipw93#

把我的案子发出去,也许对某人有用:

*错误Unknown receiver 'RSJsonSymbol'; did you mean 'RSSymbol'? Replace 'RSJsonSymbol' with 'RSSymbol'
*原因:不包含头文件
*解决方案:包含其头文件RSJsonSymbol.h

相关问题