Мне нужна помощь с EXC_BAD_ACCESS
во время функции didSelectRowAtIndexPath
в UIViewController
.EXC_BAD_ACCESS после didSelectRowAtIndexPath
Свойства:
@property (strong, nonatomic) Album *selectedAlbum;
@property (strong, nonatomic) NSMutableArray *artistAlbums;
@property (weak, nonatomic) IBOutlet UITableView *albums;
загружающего NSMutableArray
"связан" с UITableView
:
- (void) loadAlbums {
self.artistAlbums = [self.albumService getAlbumsFromDatabase];
for (Album * album in self.artistAlbums) {
// No error
NSLog(album.title);
NSLog(album._id);
}
}
AlbumService, getAlbumsFromDatabase
:
- (NSMutableArray *)getAlbumsFromDatabase: {
NSMutableArray * result = [@[] mutableCopy];
// FavAlbumDpo.id is NSNumber
for (FavAlbumDpo *albumdpo in [self.databaseManager getAllAlbums]) {
Album *album1 = [[Album alloc]init];
album1._id = [albumdpo.id stringValue];
album1.title = albumdpo.title;
[result addObject:album1];
}
return result;
}
Функция didSelectRowAtIndexPath
:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
self.selectedAlbum = self.artistAlbums[indexPath.row];
for (Album * album in self.artistAlbums) {
NSLog(album.title); // Print the title
NSLog(album._id); // EXC_BAD_ACCESS
}
[self performSegueWithIdentifier:SEGUE_ID sender:self];
}
Album.h
:
@interface Album : NSObject
@property (strong, nonatomic) NSString *title;
@property (assign, nonatomic) NSString *_id;
@end
Album.m
:
@implementation Album
- (instancetype)init{
self = [super init];
if (self){
self.title = @"title";
self._id = @"id";
}
return self;
}
@end
Существует мало информация здесь. Какой тип _id? Вы используете ARC или нет? Может ли _id быть нуль? – amahfouz
Просьба указать строку кода, которую вы используете для объявления переменной 'selectedAlbum' – andrewbuilder