2014-02-12 38 views
-1

之前,我要为我的英语道歉,我会解决这个问题很快;-)对象是零初始化后,

所以,我从UIView类血统的对象。在initWithFrame中,我使用对象初始化数组,但在其他方法数组中等于零。我认为这个问题与ARC有关,但不知道为什么以及如何解决它。

请,帮助初级开发者)

TNX!

是的,我用的是厦门国际银行

代码:

 #import <UIKit/UIKit.h> 

     #import "MYRegistrationView.h" 

     @interface MYSelectDayView : UIView <RegisterViewDelegate> 

     //property 
     @property (strong, nonatomic)   NSNumber *weekday; 
     @property (strong, nonatomic)   NSMutableArray *arrayOfButtons; 

     //Buttons 
     @property (weak, nonatomic) IBOutlet UIButton *mondayButton; 
     @property (weak, nonatomic) IBOutlet UIButton *tuesdayButton; 
     @property (weak, nonatomic) IBOutlet UIButton *wednesdayButton; 
     @property (weak, nonatomic) IBOutlet UIButton *thursdayButton; 
     @property (weak, nonatomic) IBOutlet UIButton *fridayButton; 
     @property (weak, nonatomic) IBOutlet UIButton *saturdayButton; 
     @property (weak, nonatomic) IBOutlet UIButton *sundayButton; 

     //Action 
     - (IBAction)selectWeekday:(id)sender; 

     //methods 
     - (void) getDaysOfTraining: (NSArray *) array; 



     @end 

     #import "MYSelectDayView.h" 
     #import "MYRegistrationView.h" 

     @implementation MYSelectDayView 

     @synthesize weekday; 

     @synthesize arrayOfButtons; 

     @synthesize mondayButton; 
     @synthesize tuesdayButton; 
     @synthesize wednesdayButton; 
     @synthesize thursdayButton; 
     @synthesize fridayButton; 
     @synthesize saturdayButton; 
     @synthesize sundayButton; 

     - (id)initWithFrame:(CGRect)frame 
     { 
      self = [super initWithFrame:frame]; 
      if (self) { 
       // Initialization code 
      } 

      weekday = [[NSNumber alloc] init]; 


      mondayButton = [[UIButton alloc] init]; 
      tuesdayButton = [[UIButton alloc] init]; 
      wednesdayButton = [[UIButton alloc] init]; 
      thursdayButton = [[UIButton alloc] init]; 
      fridayButton = [[UIButton alloc] init]; 
      saturdayButton = [[UIButton alloc] init]; 
      sundayButton = [[UIButton alloc] init]; 

      arrayOfButtons = [[NSMutableArray alloc] initWithObjects:mondayButton, 
                   tuesdayButton, 
                   wednesdayButton, 
                   thursdayButton, 
                   fridayButton, 
                   saturdayButton, 
                   sundayButton,  nil]; 

      return self; 
     } 

     - (IBAction)selectWeekday:(id)sender { 

      weekday =[NSNumber numberWithInt:[sender tag]]; 

     } 

     - (void) getDaysOfTraining: (NSArray *) array { 
      for (int i=0; i<7; i++) { 
       if ([array objectAtIndex:i]==[NSNumber numberWithBool:1]) { 
        [[arrayOfButtons objectAtIndex:i] setEnabled: YES]; 
        NSLog(@"1"); 
       } 
       else { 
        [[arrayOfButtons objectAtIndex:i] setEnabled: NO]; 
        NSLog(@"0"); 
       } 
      } 
      NSLog(@"OK"); 
     } 
     @end 
+3

也请添加相关代码。 –

+0

显示相关的代码 –

+0

显示init方法和你在哪里调用它(或者你使用XIB/storyboard)? – Wain

回答

1

由于您使用IBOutlet我期待你的观点是在厦门国际银行或情节串连图板创建。因此,initWithFrame:将不会被调用(将调用initWithCoder:来取消存档视图)。你也不应该创建一组全新的按钮(它没有目标/动作/标题,也不会添加为子视图)。

删除您initWithFrame:并替换为:

- (void)awakeFromNib 
{ 
    self.arrayOfButtons = [[NSMutableArray alloc] initWithObjects:mondayButton, 
                    tuesdayButton, 
                    wednesdayButton, 
                    thursdayButton, 
                    fridayButton, 
                    saturdayButton, 
                    sundayButton, 
                    nil]; 
}