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

ios - 设置动态值后如何将数据保存到ios中的plist中?


                                            <p><pre><code>&lt;plist version=&#34;1.0&#34;&gt;
    &lt;dict&gt;
            &lt;key&gt;InfoValue&lt;/key&gt;
            &lt;string&gt;false&lt;/string&gt;
            &lt;key&gt;AudioValue&lt;/key&gt;
            &lt;string&gt;true&lt;/string&gt;
            &lt;key&gt;VideoValue&lt;/key&gt;
            &lt;string&gt;true&lt;/string&gt;
            &lt;key&gt;DescValue&lt;/key&gt;
            &lt;string&gt;true&lt;/string&gt;
            &lt;key&gt;LinkValue&lt;/key&gt;
            &lt;string&gt;true&lt;/string&gt;
   &lt;/dict&gt;
&lt;/plist&gt;
</code></pre>

<p>这是 plist 文件,我想动态更改 InfoValue。在我的代码中,我正在使用类似</p>

<pre><code>settingsPath=[ pathForResource:@&#34;SettingsValue&#34; ofType:@&#34;plist&#34;];
settingsItem = [ initWithContentsOfFile:settingsPath];

;
</code></pre>

<p>在这之后</p>

<pre><code>;
</code></pre>

<p>但它没有将数据保存到 plist 文件中。而不是我收到以下错误:</p>

<pre><code>-: unrecognized selector sent to instance 0x8fad490
2013-02-27 10:26:44.479 vCamView *** Terminating app due to uncaught exception &#39;NSInvalidArgumentException&#39;,
reason: &#39;-: unrecognized selector sent to instance 0x8fad490&#39;
*** First throw call stack:
(0x33dc012 0x2944e7e 0x34674bd 0x33cbbbc 0x33cb94e 0x2354915 0x23548b9 0x2354872
   0x235468f 0x1e207 0x2958705 0x188f920 0x188f8b8 0x1950671 0x1950bcf 0x1a90747
   0x2342e83 0x339b376 0x339ae06 0x3382a82 0x3381f44 0x3381e1b 0x376f7e3 0x376f668
   0x188c65c 0x27e2 0x2715)
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>您不能修改包内的文件。它是只读的。尝试将 plist 保存在 <code>DocumentDirectory</code> </p>

<pre><code>    NSString *directoryPath = ;
    NSString *filePath = ;

   // Read from document directory
    settingsItem = [ initWithContentsOfFile:filePath];

    // update the dictionary
    ;

   // write back to file
    ;
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 设置动态值后如何将数据保存到ios中的plist中?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/15104646/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/15104646/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 设置动态值后如何将数据保存到ios中的plist中?