UIViewController没有可见的@interface声明选择器'initWithFrame:'

时间:2015-03-04 13:56:05

标签: ios objective-c

我对此代码有疑问:

ViewController.h

#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#import "WheelMovementProtocol.h"

@interface ViewController : UIViewController {

}

@property int wheelNumberOfSections;
@property (weak, nonatomic)     id      <WheelMovementProtocol> delegate;
@property (strong, nonatomic)   UIView  *containerView;

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

@end

ViewController.m

#import "ViewController.h"

@interface ViewController () {

}

- (void)drawWheel;

@end

@implementation ViewController

@synthesize delegate;
@synthesize containerView;
@synthesize wheelNumberOfSections;

- (id)initWithFrame:(CGRect)frame andDelegate:(id)del withSections:(int)sectionsNumber {
    if ((self = [super initWithFrame: frame])) { // Here's the error
        self.wheelNumberOfSections = sectionsNumber;
        self.delegate = del;

        [self drawWheel];
    }

    return self;
}

- (void)drawWheel {
    self.containerView = [[UIView alloc] initWithFrame: self.frame];
    CGFloat angleRadius = 2 * M_PI / wheelNumberOfSections;

    for (int i = 0; i < wheelNumberOfSections; i++) {

    }
}

关于如何创建旋转滚轮控件的this tutorial之后我一步一步跟进,但我无法理解为什么我的代码错误

1 个答案:

答案 0 :(得分:0)

问题在于这个语句[super initWithFrame:frame]; 因为initWithFrame是UIView init方法,所以可以像

一样进行更改
- (id)initWithFrame:(CGRect)frame andDelegate:(id)del withSections:(int)sectionsNumber 
{
    if ((self = [super initWithNibName:"your nib for view controller" bundle:nil]))
    { 
      // Here's the error
      [self.view setFrame:frame];
      self.wheelNumberOfSections = sectionsNumber;
      self.delegate = del;

      [self drawWheel];
    }

    return self;
}