菜鸟教程小白 发表于 2022-12-12 13:15:21

ios - 调用 NSCash 不起作用


                                            <p><p>我不知道如何使用<code>NSCash</code>,但是我在阅读本主题后尝试过<a href="https://stackoverflow.com/questions/5755902/how-to-use-nscache/12957066#12957066" rel="noreferrer noopener nofollow">How to use NSCache</a>但它没有用。 </p>

<p>我遇到了这个问题<strong>原因:'-:尝试插入 nil 值(键:indexPath)'</strong></p>

<p>我做错了吗?</p>

<pre><code>.h

@interface ViewController : UIViewController

@property (nonatomic, strong) NSMutableArray *jsonArray;

@property (nonatomic, strong) NSMutableArray *jsonArray1;

@property (nonatomic, retain) NSCache *Cache;
</code></pre>

<hr/>

<pre><code>.m

- (void)viewDidLoad
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

      NSData *response = [ initWithContentsOfURL:];
      NSError *parseError = nil;
      jsonArray = ;
      jsonArray1 = [ init];
      Cache = [init];
      for(int i=0;i&lt;;i++)
      {
            NSString* city = [ objectForKey:@&#34;city&#34;];

            ;
      }

      dispatch_sync(dispatch_get_main_queue(), ^{

            self.title = @&#34;İller&#34;;

            ;

            jsonArray1 = ;

            ;

      });
    });
}
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>您正在初始化 jsonArray1,就在设置它之前。</p>

<pre><code> jsonArray1 = ; // here jsonArray1 = nil; hence remove this line and run your code again. Yo

; // hence you are setting nil value to this key &#34;indexpath&#34;
</code></pre>

<p>在那个教程中,他们说像</p>

<ul>
<li>要设置值,请使用以下行:</li>
</ul>

<blockquote>
<p>;</p>
</blockquote>

<ul>
<li>要检索值,请使用以下行。当您想使用该缓存值时,应使用此行</li>
</ul>

<blockquote>
<p>jsonArray1 = ;</p>
</blockquote>

<p>在你的情况下,只需评论</p>

<blockquote>
<p>jsonArray1 = ;</p>
</blockquote>

<p>行并再次运行。它不会给出那个错误。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 调用 NSCash 不起作用,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/18014080/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/18014080/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 调用 NSCash 不起作用