Iphone 执行错误访问错误,内存管理问题
我已经读到,这个错误来自内存管理问题,例如向已释放的对象发送消息。在第二个“for”部分的第一行中的注释“output information about somes in'info'array”之后,我得到了错误。信息数组是否没有存储我在第一个“for”部分中提供的对象 还有其他想法吗Iphone 执行错误访问错误,内存管理问题,iphone,objective-c,xcode,memory-management,Iphone,Objective C,Xcode,Memory Management,我已经读到,这个错误来自内存管理问题,例如向已释放的对象发送消息。在第二个“for”部分的第一行中的注释“output information about somes in'info'array”之后,我得到了错误。信息数组是否没有存储我在第一个“for”部分中提供的对象 还有其他想法吗 MPMediaQuery *query = [[MPMediaQuery alloc] init]; //query iPod library NSMutableArray *info; //create ar
MPMediaQuery *query = [[MPMediaQuery alloc] init]; //query iPod library
NSMutableArray *info; //create array to hold songs that fit
NSArray *allSongs = [query collections];
//only add those songs which have not
//been played since last login
for (MPMediaItem *recent in allSongs) {
NSDate *lastPlayed = [recent valueForProperty:MPMediaItemPropertyLastPlayedDate];
BOOL uploadInfo = [[PlayedSinceLastLogin alloc] initWithLastPlayedDateOfSong:lastPlayed] ;
if (uploadInfo == YES) {
[info addObject:recent];
}
}
//output information about songs
//in the 'info' array
for (MPMediaItem *played in info) {
NSString *playCount = [played valueForProperty:MPMediaItemPropertyPlayCount];
NSString *lastPlayed = [played valueForProperty:MPMediaItemPropertyLastPlayedDate];
NSString *songTitle =
[played valueForProperty: MPMediaItemPropertyTitle];
NSString *artistName =
[played valueForProperty: MPMediaItemPropertyArtist];
NSString *albumName =
[played valueForProperty: MPMediaItemPropertyAlbumTitle];
NSLog (@"\n %@ by %@, from album %@, played since last login.\nLast Played:%@.\nTotal Play Count: %@.", songTitle, artistName, albumName, lastPlayed,playCount);
}
看起来您从未为
info
实际创建过NSMutableArray
的实例,因此错误的访问错误可能是由于试图将一些随机内存位作为初始化对象处理
改变
NSMutableArray *info;
到
顺便说一句,如果你真的有妄想症,如果你还没有准备好赋值,最好是nil init:NSMutableArray*info=nil;很不错的!我认为在方法从a-变为a+之前,它以前是ivar。非常感谢!我是否还必须创建UITextView对象的实例?当我尝试将textView.Text更改为我刚创建的字符串时,我遇到了类似的错误。是的,所有对象都必须在某个地方创建;你不能仅仅声明和使用它们。加载nib文件时,运行时会多次创建UITextView对象,但如果不是,则必须手动创建。
NSMutableArray *info = [NSMutableArray array];