Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone NSCoding帮助非常奇怪的错误访问解除分配的实例_Iphone_Ios_Objective C_Nscoding - Fatal编程技术网

Iphone NSCoding帮助非常奇怪的错误访问解除分配的实例

Iphone NSCoding帮助非常奇怪的错误访问解除分配的实例,iphone,ios,objective-c,nscoding,Iphone,Ios,Objective C,Nscoding,在我的代码中,我将数组存储在内存中。。。无需发出HTML请求即可获取它。 第一次,当我填充数组时,一切都正常。。。当我从内存中加载数组并将其加载到表中时,问题就会出现 这就是课堂 @interface SubscriptionArray : NSObject{ NSString *title; NSString *source; NSString *htmlUrl; NSInteger count; } @property (nonatomic,retain)

在我的代码中,我将数组存储在内存中。。。无需发出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个不同的类共享)

我是这样装的

[onlySubsriptions removeAllObjects];
self.onlySubsriptions = [NSKeyedUnarchiver unarchiveObjectWithFile:fullFileName];
我在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]];
    }
例如,我确信我有2个元素,CellForRowatineXpath在开始加载第一个元素(元素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]];
    }

为了处理这种异常,您可以使用malloc工具找出僵尸并修复它。
产品>配置文件将启动仪器,然后您应该有一个名为“Malloc”的“跟踪模板”。这可能对您有用。

使用“NSZombie”检查哪个实例是DealLocate。我已经在回答中添加了一些信息。。。我不明白我的代码出了什么问题……你能帮我一下吗?-您的7行导致了问题,我可以部分地将其视为
[SubscriptionsViewController table…]
您可以发布此方法吗?我在回答中添加了一些信息。。。我不明白我的代码中有什么错误…你能帮我一下吗?我已经添加了方法的重要部分