2014-01-11 44 views
0

我一直在某個類的某些函數上獲取EXC_BAD_ACCESS。如果我更改函數的名稱,錯誤似乎消失了......但我想知道爲什麼會發生這種情況,因爲我碰巧喜歡我給我的函數的名稱。在定義的函數上獲取錯誤訪問

這是我的^ h文件 -

@property(strong, nonatomic)NSString* month; 
@property(strong,nonatomic)NSString* day; 
@property(strong,nonatomic)NSString* description; 
@property(strong,nonatomic)NSString* type; 
@property(strong,nonatomic)NSString* venue; 

@property(weak,nonatomic)IBOutlet UIImageView* imageView; 
@property(weak,nonatomic)IBOutlet UILabel* descriptionLabel; 
@property(weak,nonatomic)IBOutlet UILabel* venueLabel; 
@property(weak,nonatomic)IBOutlet UILabel* titleLabel; 
@property(weak,nonatomic)IBOutlet UILabel* typeLabel; 
@property(weak,nonatomic)IBOutlet UILabel* dateLabel; 

@property(weak,nonatomic)IBOutlet UILabel* monthLabel; 
@property(weak,nonatomic)IBOutlet UILabel* dayLabel; 

-(void)setDate:(NSString*)month withDay:(NSString*)day; 
-(void)setImage:(UIImage*)image; 

這些都是我制定者 -

-(void)setDescription:(NSString *)description{ 
    self.description = description; 
    self.descriptionLabel.text = description; 
} 

-(void)setTitle:(NSString *)title{ 
    self.title = title; 
    self.titleLabel.text = title; 
} 

-(void)setType:(NSString *)type{ 
    self.type = type; 
    self.typeLabel.text = type; 
} 


-(void)setVenue:(NSString *)venue{ 
    self.venue = venue; 
    self.venueLabel.text = venue; 
} 

-(void)setDate:(NSString *)month withDay:(NSString *)day{ 
    self.month = month; 
    self.day = day; 
} 

-(void)setImage:(UIImage*)image{ 
    self.imageView.image = image; 
} 



- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 
} 

-(void)viewWillAppear:(BOOL)animated{ 
    self.monthLabel.text = self.month; 
    self.dayLabel.text = self.day; 
} 

如果我運行這一點 - 我得到一個的setTitle EXC_BAD_ACCESS。如果我將其更改爲setEventTitle,則錯誤消失,並在setVenue上獲得EXC_BAD_ACCESS。

這是我如何調用這些職能 -

-(UIView*)getEventResultView:(NSDictionary*)component{ 
EventViewController* eventVC = [[EventViewController alloc] initWithNibName:@"EventResultView" bundle:nil]; 
NSDictionary* dateDictionary = someDate; 
NSString* month= [self findMonth:dateDictionary]; 
[eventVC setDate:month withDay:someDay]; 
[eventVC setTitle: someTitle]; 
[eventVC setVenue: someVenue]; 
[eventVC setDescription:someDescription]; 

NSString* titleImageUrl = someUrl; 
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul); 

dispatch_async(queue, ^{ 
    NSData *titleImageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:titleImageUrl]]; 
    UIImage* titleImage = [UIImage imageWithData:titleImageData]; 
    [eventVC setImage: titleImage]; 
}); 

return eventVC.view; 

}

這究竟是爲什麼?

回答

3

你有一個無限遞歸:

-(void)setType:(NSString *)type 
{ 
    self.type = type; 
    … 
} 

正是在這裏:

self.type = …; 

[self setType:…]; 

因此該方法的縮寫形式(有中沒有功能的代碼)在執行時被調用。

這樣做:

-(void)setType:(NSString *)type 
{ 
    _type = type; 
    … 
} 
+0

...,並確保已啓用ARC。 – bbum

+0

...並確保您沒有將MM切換到手動內存管理?我很確定他沒有改變默認設置。 ;-) –

+0

除非OP使用舊的代碼庫,舊的模板,以舊的在線示例開始,或者從互聯網上不良的建議的衆多來源之一採取一些不好的建議...... :) – bbum