gpt4 book ai didi

ios - 对定义的函数进行错误访问

转载 作者:行者123 更新时间:2023-11-28 20:08:49 25 4
gpt4 key购买 nike

我一直在类中的某些函数上收到 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;

为什么会这样?

最佳答案

你有一个无限递归:

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

}

它在这里:

self.type = …;

的缩写形式
[self setType:…];

因此该方法(您的代码中没有函数)在执行时被调用。

这样做:

-(void)setType:(NSString *)type
{
_type = type;

}

关于ios - 对定义的函数进行错误访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21057968/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com