2015-03-04 3 views
-2

У меня проблема с этим кодом:Нет видимых @interface для UIViewController заявляет селектор 'initWithFrame:'

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

'UIViewController' не имеет метод, называемый' 'initWithFrame:. Поэтому вы не можете выполнять '[super initWithFrame: frame]', если ваш объект наследуется от 'UIViewController'. – Larme

+1

Ваш суперкласс - UIViewController в tutotial, он подклассифицируется из UIControl – iOSfleer

+0

«Решение должно было снова следовать учебнику и правильно создать ViewController». это весело :-) – Alf

ответ

0

Проблема с этим утверждением [super initWithFrame: frame]; Поскольку initWithFrame является UIView метод инициализации вы можете изменить его, как

- (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; 
} 
Смежные вопросы