1

在我的代码中,我将我的数组存储在内存中...无需发出 HTML 请求即可获得它。第一次,当我填充我的数组时,一切都很好......当我从内存中加载数组并将它们加载到表中时,问题就出现了。

就是这样的课

@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"];

}

该数组在委托中声明(与 3 个不同的类共享)为

 NSMutableArray *onlySubsriptions; @property(nonatomic, retain)
 NSMutableArray *onlySubsriptions;

我以这种方式加载它

[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]];
    }
4

1 回答 1

0

处理这种异常,可以使用malloc工具找出僵尸并修复它。Product > Profile 将启动 Instruments,然后您应该有一个名为“Malloc”的“Trace Template”。这个问题可能对你有用。

于 2013-07-21T04:36:12.597 回答