ios - iPhone 应用程序错误预期标识符或 '('

标签 ios objective-c

<分区>


想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post .

关闭 9 年前

我一直在四处寻找,但还没有想出太多。表示存在预期的标识符错误。这是唯一的错误。任何帮助将不胜感激。

我只是有点困惑,我不确定是不是因为我看了太久,它一直给我解析错误。

这是我的.h

#import <UIKit/UIKit.h>
#import "AMRotaryProtocol.h"

@interface AMRotaryWheel : UIControl
-(void)drawWheel;
@property (weak) id <AMRotaryProtocol> delegate;
@property (nonatomic, strong) UIView *container;
@property int numberOfSections;

- (id) initWithFrame:(CGRect)frame andDelegate:(id)del withSections:(int)sectionsNumber;

@end

和.m

#import <QuartzCore/QuartzCore.h>
#import "AMRotaryWheel.h"

@interface AMRotaryWheel()

- (void) drawWheel
{
    // 1
    container = [[UIView alloc] initWithFrame:self.frame];
    // 2
    CGFloat angleSize = 2*M_PI/numberOfSections;
    // 3
    for (int i = 0; i < numberOfSections; i++) {
        // 4
        UILabel *im = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 40)];
        im.backgroundColor = [UIColor redColor];
        im.text = [NSString stringWithFormat:@"%i", i];
        im.layer.anchorPoint = CGPointMake(1.0f, 0.5f);
        // 5
        im.layer.position = CGPointMake(container.bounds.size.width/2.0,
                                        container.bounds.size.height/2.0);
        im.transform = CGAffineTransformMakeRotation(angleSize * i);
        im.tag = i;
        // 6
        [container addSubview:im];
    }
    // 7
    container.userInteractionEnabled = NO;
    [self addSubview:container];
}

@end

@implementation AMRotaryWheel

@synthesize delegate, container, numberOfSections;

- (id) initWithFrame:(CGRect)frame andDelegate:(id)del withSections:(int)sectionsNumber {
// 1 - Call super init
if ((self = [super initWithFrame:frame])) {
    // 2 - Set properties
    self.numberOfSections = sectionsNumber;
    self.delegate = del;
    // 3 - Draw wheel
    [self drawWheel];
}
return self;
}

- (void) drawWheel {

}

@end

感谢大家的帮助。

最佳答案

您的方法体在您的@interface (.h) 文件中,而您应该只在头文件中包含您的方法原型(prototype)。方法体应位于相应的@implementation (.m)文件中。

所以在 AMRotaryWheel.h 中你应该有:

@interface AMRotaryWheel()
-(void) drawWheel;
@end

AMRotaryWheel.m 中你应该有:

@implementation AMRotaryWheel
-(void) drawWheel {
  // method body here
}
@end

关于ios - iPhone 应用程序错误预期标识符或 '(',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17014751/

上一篇:iphone - 尽管我添加了显示,但无法在 iPhone 中显示 UIAlertView

下一篇:ios - 需要在启用 ARC 的情况下使用 Leaks 进行分析吗?

相关文章:

ios - 架构 armv7 的 undefined symbol : "_OBJC_CLASS_$_Crashlytics", 从 : objc-class-ref in AppDelegate. o 引用

objective-c - 协议(protocol)在内部是如何实现的?

ios - 从 UIBezierPath 获取所有点(不仅仅是控制点)

ios - 来自 UITableViewCell 中的按钮的 UIPopoverPresentationController

iphone - 在 viewDidLoad 中的子类之后, [super viewDidLoad] 被调用,但方法没有被执行

iphone - 以编程方式设置 UIToolBar

ios - 在 Swift 3.0 中创建目录

javascript - iOS 浏览器 - 当使用 JavaScript 更改 css 或内容时,iFrame 跳转到顶部

ios - scrollsToTop 和屏幕上的多个 scrollViews

ios - Keychain和iOS版本升级