我一直在試圖調試這個錯誤,就像幾天一樣,似乎仍然無法理解我的對象究竟在做什麼。代碼如下所示。 - (BOOL)web視圖:(的UIWebView *)webView的shouldStartLoadWithRequest:(的NSURLRequest *)請求navigationType:(UIWebViewNavigationType)navigationType {從點擊鏈接 //提取數據我的自定義類對象即使在保留後也會被釋放
SongObject *數據= [[SongObject的alloc] INIT]; [數據保留]; selectedSong = Data; }
selectedSong是主類中的公共變量,現在瘋狂的事情是使用上述方法在其他地方工作,但是使用了shoulStartLoadWithRequest。
試圖解除它給我「超出範圍」,可能是因爲一些瘋狂的原因,「shouldStartLoadWithRequest」會自動釋放我的對象,即使我說不要?
任何想法的?
編輯:這是H和M文件,其中選擇宋被認爲是舉行。
#import <Foundation/Foundation.h>
#import "SongObject.h"
@interface SongObject : NSObject<NSCopying> {
NSString *artist;
NSString *titel;
NSString *album;
NSString *genre;
NSString *songUrl;
NSString *rating;
NSString *image;
BOOL local;
}
@property (readonly) NSString *getArtist;
@property (readonly) NSString *getTitle;
@property (readonly) NSString *getAlbum;
@property (readonly) NSString *getGenre;
@property (readonly) NSString *getSongURL;
@property (readonly) NSString *getRating;
@property (readonly) NSString *getImage;
@property (readonly) BOOL isLocal;
-(void) setInfo:(NSString *) a: (NSString*) t: (NSString*) ab: (NSString*)g: (NSString*)sU: (NSString*)r: (NSString*) i: (BOOL) loc;
@end
#import "SongObject.h"
@implementation SongObject
-(id)init
{
if(self =[super init])
{
NSLog(@"Init songobject");
}
return self;
}
-(id) copyWithZone: (NSZone *) zone {
SongObject *newSong = [[SongObject allocWithZone:zone] init];
NSLog(@"_copy: %@", [newSong self]);
[newSong setInfo:[self getArtist] :[self getTitle] :[self getAlbum] :[self getGenre] :[self getSongURL] :[self getRating] :[self getImage] :[self isLocal]];
return(newSong);
}
-(void)dealloc
{
NSLog(@"Songobject deallocted from memory...");
[super dealloc];
}
-(void) setInfo:(NSString *) a: (NSString*) t: (NSString*) ab: (NSString*)g: (NSString*)sU: (NSString*)r: (NSString*) i: (BOOL) loc{
artist = a;
titel = t;
album = ab;
genre = g;
songUrl = sU;
rating = r;
image = i;
local = loc;
}
-(NSString*)getArtist
{
return artist;
}
-(NSString*)getTitle
{
return titel;
}
-(NSString*)getAlbum
{
return album;
}
-(NSString*)getGenre
{
return genre;
}
-(NSString*)getSongURL
{
return songUrl;
}
-(NSString*)getRating
{
return rating;
}
-(NSString*)getImage
{
return image;
}
-(BOOL)isLocal{
return local;
}
@end
這是selectedSong應該保存的類文件。 – 2011-02-10 20:45:34