在我的代碼中,我在內存中存儲我的數組...無需提交HTML請求即可獲取它。 第一次,當我填充我的數組時,一切正常......當我從內存加載數組並將它們加載到表中時出現問題。NSCoding幫助非常奇怪的錯誤訪問釋放的實例
這是
@interface SubscriptionArray : NSObject{
NSString *title;
NSString *source;
NSString *htmlUrl;
NSInteger count;
}
@property (nonatomic,retain) NSString *title;
@property (nonatomic,retain) NSString *source;
@property (nonatomic,retain) NSString *htmlUrl;
@property (nonatomic) NSInteger count;
@end
#import "SubscriptionArray.h"
@implementation SubscriptionArray
@synthesize title,source,htmlUrl,count;
-(void)dealloc{
[title release];
[source release];
[htmlUrl release];
}
#pragma mark NSCoding
- (id)initWithCoder:(NSCoder *)decoder {
if (self = [super init]) {
title = [[decoder decodeObjectForKey:@"title"] retain];
source = [[decoder decodeObjectForKey:@"source"] retain];
htmlUrl = [[decoder decodeObjectForKey:@"htmlUrl"] retain];
count = [decoder decodeIntegerForKey:@"count"];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)encoder {
if (title) [encoder encodeObject:title forKey:@"title"];
if (source) [encoder encodeObject:source forKey:@"source"];
if (htmlUrl) [encoder encodeObject:htmlUrl forKey:@"htmlUrl"];
if (count) [encoder encodeInteger:count forKey:@"count"];
}
陣列處於委託聲明的類作爲
NSMutableArray *onlySubsriptions; @property(nonatomic, retain)
NSMutableArray *onlySubsriptions;
(與3個不同的類共享)我加載它以這種方式
[onlySubsriptions removeAllObjects];
self.onlySubsriptions = [NSKeyedUnarchiver unarchiveObjectWithFile:fullFileName];
並且我在cellForRowAtIndexPath中收到錯誤
例如我確信我有2個元素,cellForRowAtIndexPath在它開始加載第一個元素(元素0)時拋出一個異常......它表示釋放實例。
我敢肯定,問題是在編碼上,因爲第一次當我得到數組一切都很好......只有當下次加載我在本地存儲的數組時,問題纔會顯示出來。
****更多關於******
****的cellForRowAtIndexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
TDBadgedCell *cell = [[[TDBadgedCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
SubscriptionArray * element=[[SubscriptionArray alloc]init];
if (indexPath.section==0) {
NSLog(@"CASO SPECIALELEMENTS");
element =[delegate.reader.specialElements objectAtIndex:[indexPath row]];
}
if (indexPath.section==1) {
NSLog(@"CASO CATEGORIA");
element =[delegate.reader.categories objectAtIndex:[indexPath row]];
}
if (indexPath.section==2) {
NSLog(@"CASO SUBSCRIPTIONS");
element =[delegate.reader.onlySubsriptions objectAtIndex:[indexPath row]];
}
使用'NSZombie'來檢查哪個實例被釋放 –
我已經添加了一些信息給我的答案...我不明白我的代碼中有什麼問題...你能幫助我嗎? - –
您的7行導致問題,我可以看到部分'[SubscriptionsViewController表...]'你可以發佈此方法嗎? –