在EXC_BAD_ACCESS
的{{1}}功能期间,我需要didSelectRowAtIndexPath
的帮助。
属性:
UIViewController
将@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);
}
}
:
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
答案 0 :(得分:1)
您的_id属性字符串已取消分配。变化
@property (assign, nonatomic) NSString *_id;
到
@property (strong, nonatomic) NSString *_id;