[__NSArrayI objectAtIndex:]:发送到释放实例 0x7fbdae1a2080 的消息
[__NSArrayI objectAtIndex:]: message sent to deallocated instance 0x7fbdae1a2080
在 tableView
中,我有一些对象显示得很好。但是,当我与列表交互并向下(向前)滚动时,应用程序将崩溃。我以前从未见过这种情况,也不知道为什么会这样。我将第 3 方日历与我的代码结合使用,我想我应该提到这一点,但我认为这不是主要问题。
#import "VRGViewController.h"
@interface VRGViewController ()
@end
@implementation VRGViewController{
NSArray *calendarTableData;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
VRGCalendarView *calendar = [[VRGCalendarView alloc] init];
calendar.delegate=self;
calendar.center = self.view.center;
[self.view addSubview:calendar];
calendarTableData = [NSArray arrayWithObjects:@"Egg Benedict", @"Mushroom Risotto",nil];
}
-(void)calendarView:(VRGCalendarView *)calendarView switchedToMonth:(int)month targetHeight:(float)targetHeight animated:(BOOL)animated {
if (month==[[NSDate date] month]) {
NSArray *dates = [NSArray arrayWithObjects:[NSNumber numberWithInt:1],[NSNumber numberWithInt:5], nil];
[calendarView markDates:dates];
}
}
-(void)calendarView:(VRGCalendarView *)calendarView dateSelected:(NSDate *)date {
NSLog(@"Selected date = %@",date);
}
#pragma mark - User Defined Methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [calendarTableData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *simpleTableIdentifier = @"Services";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [calendarTableData objectAtIndex:indexPath.row];
return cell;
}
@end
您必须按以下方式声明您的数据源:
calendarTableData = [[NSArray alloc]initWithObjects:@"Egg Benedict",
@"Mushroom Risotto",nil];
问题出在我调用数组的方式上。
因为我使用的是第 3 方代码,所以我禁用了 ARC。这导致了我如何调用我的对象数组的问题。感谢@meda 帮助我提供答案 - 在我实施它之后我才意识到我错在哪里
在 tableView
中,我有一些对象显示得很好。但是,当我与列表交互并向下(向前)滚动时,应用程序将崩溃。我以前从未见过这种情况,也不知道为什么会这样。我将第 3 方日历与我的代码结合使用,我想我应该提到这一点,但我认为这不是主要问题。
#import "VRGViewController.h"
@interface VRGViewController ()
@end
@implementation VRGViewController{
NSArray *calendarTableData;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
VRGCalendarView *calendar = [[VRGCalendarView alloc] init];
calendar.delegate=self;
calendar.center = self.view.center;
[self.view addSubview:calendar];
calendarTableData = [NSArray arrayWithObjects:@"Egg Benedict", @"Mushroom Risotto",nil];
}
-(void)calendarView:(VRGCalendarView *)calendarView switchedToMonth:(int)month targetHeight:(float)targetHeight animated:(BOOL)animated {
if (month==[[NSDate date] month]) {
NSArray *dates = [NSArray arrayWithObjects:[NSNumber numberWithInt:1],[NSNumber numberWithInt:5], nil];
[calendarView markDates:dates];
}
}
-(void)calendarView:(VRGCalendarView *)calendarView dateSelected:(NSDate *)date {
NSLog(@"Selected date = %@",date);
}
#pragma mark - User Defined Methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [calendarTableData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *simpleTableIdentifier = @"Services";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [calendarTableData objectAtIndex:indexPath.row];
return cell;
}
@end
您必须按以下方式声明您的数据源:
calendarTableData = [[NSArray alloc]initWithObjects:@"Egg Benedict",
@"Mushroom Risotto",nil];
问题出在我调用数组的方式上。
因为我使用的是第 3 方代码,所以我禁用了 ARC。这导致了我如何调用我的对象数组的问题。感谢@meda 帮助我提供答案 - 在我实施它之后我才意识到我错在哪里