iphone - 将文本框数据写入 Plist
<p><p>我有两个文本框,当我按下提交时,我想将此文本框的数据存储到 Plist 中。
到目前为止我已经完成了编写代码,但问题是如何编写文本框的数据?就像我有 textbox1 和 textbox2 一样。想将数据存储到 plist 中</p>
<pre><code>NSString *filePath = [ pathForResource:@"Comments" ofType:@"plist"];
NSMutableArray *plistArray = [ initWithContentsOfFile:filePath];
NSMutableDictionary *newComment = ;
;
;
;
;
</code></pre>
<p>请给我正确的方法</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>让你的文本框成为 textbox1 和 textbox2</p>
<pre><code>- (IBAction) saveData
{
// get paths from root direcory
NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
// get documents path
NSString *documentsPath = ;
// get the path to our Data/plist file
NSString *plistPath = ;
// set the variables to the values in the text fields
self.title = textbox1.text;
self.comment = textbox2.text;
// create dictionary with values in UITextFields
NSDictionary *plistDict = forKeys:];
NSString *error = nil;
// create NSData from dictionary
NSData *plistData = ;
// check is plistData exists
if(plistData)
{
// write plistData to our Data.plist file
;
}
else
{
NSLog(@"Error in saveData: %@", error);
;
}
}
</code></pre></p>
<p style="font-size: 20px;">关于iphone - 将文本框数据写入 Plist,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/13738054/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/13738054/
</a>
</p>
页:
[1]