簡體   English   中英

Xcode Objective-C 錯誤需要一些幫助:)

[英]Xcode objective-C errors need some help :)

好吧,我一直在努力解決這個問題,我設法將其歸結為這 3 個錯誤,我一直在尋找解決方法,但沒有任何工作可以幫助我解決這個問題嗎?

我正在嘗試編譯一些東西,這是其中的一部分,這是我需要修復的全部內容才能使其正常工作,但我不知道該怎么做。

這也不是我的代碼,如果您想查看原始鏈接,請點擊鏈接信用轉到 Hamzasood

Hamzasood 定制表盤

我把錯誤放在代碼旁邊,所以尋找 <---//ERROR there only 3

以下是 1.OnozOmgEditingGuideView.h 下面的文件

//
//  OnozOmgEditingGuideView.h
//  CustomWatchFaceTest
//
//  Created by Hamza Sood on 17/08/2015.
//  Copyright © 2015 Hamza Sood. All rights reserved.


#import <UIKit/UIKit.h>
@class

@interface OnozOmgEditingGuideView : UIView {   <---//expected identifier
    UIView *_topView;
    UILabel *_topLabel;

    UIView *_bottomView;
    UILabel *_bottomLabel;
}
@end
/*!
 Set the color shown by the top view.
    The new color to be displayed
*/
- (void)setTopColor:(UIColor *)color;

/*!
 Set the color shown by the bottom view.
 @param color
    The new color to be displayed
 */
- (void)setBottomColor:(UIColor *)color;   <---//missing content for method declaration

它缺少內容並且正在尋找一些東西,但我不知道我真的很陌生。

2.OnozOmgEditingGuideView.m

//
//  OnozOmgEditingGuideView.m
//  CustomWatchFaceTest
//
//  Created by Hamza Sood on 17/08/2015.
//  Copyright © 2015 Hamza Sood. All rights reserved.
//

#import "OnozOmgEditingGuideView.h"

@implementation OnozOmgEditingGuideView {    <---//Expected Method Body
/*
 Initial setup steps:
    1. Create the views and their corresponding labels
    2. Set the label text
    3. Constrain the views
*/
- (instancetype)initWithFrame:(CGRect)frame {
    if ((self = [super initWithFrame:frame])) {

        // 1
        __strong UIView  **viewsToCreate[]  = { &_topView,       &_bottomView };
        __strong UILabel **labelsToCreate[] = { &_topLabel, &_bottomLabel };
        for (int i = 0; i < sizeof(viewsToCreate)/sizeof(UIView**); i++) {
            UIView *view = [[UIView alloc]initWithFrame:CGRectZero];
            [view setTranslatesAutoresizingMaskIntoConstraints:NO];
            [self addSubview:view];

            UILabel *label = [[UILabel alloc]initWithFrame:CGRectZero];
            [label setTranslatesAutoresizingMaskIntoConstraints:NO];
            [view addSubview:label];

             NSLayoutAttribute labelAttributesToConstrain[] = { NSLayoutAttributeCenterX, NSLayoutAttributeCenterY };
            for (int j = 0; j <     sizeof(labelAttributesToConstrain)/sizeof(NSLayoutAttribute); j++) {
                NSLayoutConstraint *constraint = [NSLayoutConstraint   constraintWithItem:label
                                                                                  attribute:labelAttributesToConstrain[j]
                                                                                 relatedBy:NSLayoutRelationEqual
                                                                                     toItem:view
                                                                                attribute:labelAttributesToConstrain[j]
                                                                             multiplier:1
                                                                                  constant:0];
                [constraint setActive:YES];
            }

            *viewsToCreate[i] = view;
            *labelsToCreate[i] = label;
        }

        // 2
        [_topLabel setText:@"First Colour"];
        [_bottomLabel setText:@"Second Colour"];

        // 3
        NSString *constraintsToAdd[] = {
            @"H:|[_topView]|",
            @"H:|[_bottomView]|",
            @"V:|[_topView]-(0)-[_bottomView(==_topView)]|"
        };
        NSDictionary *constraintsViewsDictionary =  NSDictionaryOfVariableBindings(_topView, _bottomView);
        for (int i = 0; i < sizeof(constraintsToAdd)/sizeof(NSString*); i++) {
            [NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:constraintsToAdd[i]
                                                                                                options:0
                                                                                             metrics:nil
                                                                                               views:constraintsViewsDictionary]];
        }
    }
    return self;
}
@class
- (void)setTopColor:(UIColor *)color {
    [_topView setBackgroundColor:color];
}

- (void)setBottomColor:(UIColor *)color {
    [_bottomView setBackgroundColor:color];
}

@end

這一個給出了預期的方法體

就像我說的我不擅長這個所以如果你能幫忙:)

在 .h 的頂部,您有@class編譯器指令,但沒有為您正在前向聲明的類提供名稱。 @class用於“前向聲明”一個類,它告訴編譯器“另一個類 X 將存在,所以不要抱怨還不知道所有細節。” 由於您沒有提供名稱,編譯器會感到困惑,因此您會在下一行看到錯誤。 看到這個問題: Objective-C: @class Directive before @interface?

在 .m 的底部,出於某種原因,您再次擁有 @class ......但錯誤似乎是因為您在@implementation之后放置了一個開放的花括號{ ,直到所有方法之后才關閉。 那不應該在那里。 如果要聲明實例變量,請在 @implementation 后使用花括號。 對於方法來說不是必需的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM