-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
也請添加相關代碼。 –
顯示相關的代碼 –
顯示init方法和你在哪裏調用它(或者你使用XIB/storyboard)? – Wain