菜鸟教程小白 发表于 2022-12-12 18:03:09

iphone - NSArray 给出 NSZombie 错误


                                            <p><p>我正在尝试将单个数组对象(即多个值的字典)传递回我的主视图。</p>

<p>基本上,当我设置 View 时,我会将一些 xml 解析为字典数组。然后,我使用 NSdictionary 中的一个值设置我的 tableview,该值也用于设置按字母顺序排列的滚动条和部分标题。 (这是在我创建的方法中完成的)</p>

<p>在该方法结束时,我调用 ;一切都完美加载,一切都很好。</p>

<p>现在我要做的是设置它,以便在选择单元格时检查 cell.textlabel 中的值,并在找到相应条目后将其用作谓词来检查我的字典数组我想通过我创建的委托(delegate)将该字典传递到主视图。</p>

<p>但是我收到了一个错误,我认为这可能是由于我的 reloadData.. 但我不确定。
这就是我的谓词的样子。</p>

<pre><code>NSPredicate *pred = ;
            NSArray *filter = ; //error happens here
            //check to see if the value is the correct one
            NSLog(@&#34;My Filtered array = %@&#34;, filter);
            //once problem has been found set up the delegate here.
</code></pre>

<p>这是我收到的错误消息。</p>

<pre><code>2011-10-31 10:43:57.333 code *** -: message sent to deallocated instance 0x6874210
</code></pre>

<p>myDataArray 是在 NSXMLParser 委托(delegate)中创建的,如下所示。</p>

<p>//.h</p>

<pre><code>NSMutableArray *myDataArray;
}
@property (nonatomic, retain) NSMutableArray *myDataArray;
</code></pre>

<p>//.m</p>

<pre><code>#pragma mark - Parsing lifecycle

- (void)startTheParsingProcess:(NSData *)parserData
{

    //myDataArray = ; // not even sure if this is needed as its declared later on.

    NSXMLParser *parser = [ initWithData:parserData]; //parserData passed to NSXMLParser delegate which starts the parsing process

    ;
    ; // starts the event-driven parsing operation.
    ;
}

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
    if()
    {
      manufactureMutableDictionary = [ initWithDictionary:attributeDict];
    }
    if()
    {
      myDataArray = ;
    }
}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
    if()
    {
      ;
    }
    ;
    manufactureMutableDictionary = nil;
}
</code></pre>

<p>任何帮助将不胜感激,您认为我会以正确的方式传递字典的所有值吗?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>您正在使用 <code>autorelease</code>d 数组</p>

<pre><code>myDataArray = ;
</code></pre>

<p>您已设置属性,因此请使用它们,例如</p>

<pre><code>self.myDataArray = ;
</code></pre>

<p>甚至更好</p>

<pre><code>NSMutableArray *tmpMyDataArray = [ initWithCapacity:8];
self.myDataArray = tmpMyDataArray;
; tmpMyDataArray = nil;
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于iphone - NSArray 给出 NSZombie 错误,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/7948075/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/7948075/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iphone - NSArray 给出 NSZombie 错误