didSelectRowAtIndexPath之后的EXC_BAD_ACCESS

时间:2015-03-04 21:47:20

标签: ios objective-c uitableview

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

1 个答案:

答案 0 :(得分:1)

您的_id属性字符串已取消分配。变化

@property (assign, nonatomic) NSString *_id;

@property (strong, nonatomic) NSString *_id;