• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            posts - 319, comments - 22, trackbacks - 0, articles - 11
              C++博客 :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

            功能創(chuàng)建一個(gè)test.plist文件,textInput作為輸入,displayLabel作為顯示,有一個(gè)按鈕來(lái)觸發(fā)保持程序triggerStorage;

            -(void)triggerStorage
            {
                displayLabel.text = textInput.text;
                
                NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
                NSString *path=[paths    objectAtIndex:0];  
                NSString *filename=[path stringByAppendingPathComponent:@"test.plist"];   //獲取路徑
                
                NSDictionary* dic2 = [NSDictionary dictionaryWithContentsOfFile:filename];  //讀取數(shù)據(jù)
                NSLog(@"dic2 is:%@",dic2); 
                
                //創(chuàng)建一個(gè)dic,寫(xiě)到plist文件里
                NSDictionary* dic = [NSDictionary dictionaryWithObjectsAndKeys:displayLabel.text,@"IP",nil]; //寫(xiě)入數(shù)據(jù)
                [dic writeToFile:filename atomically:YES];   

            }

            // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
            - (void)viewDidLoad
            {
                NSMutableArray *resultData; 
                NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
                NSString *path=[paths objectAtIndex:0];
                NSLog(@"path = %@",path);   
                NSString *filename=[path stringByAppendingPathComponent:@"test.plist"]; 
              
                //讀文件
                NSDictionary* dic2 = [NSDictionary dictionaryWithContentsOfFile:filename];
                NSLog(@"dic is:%@",dic2);    
                if(dic2 == nil)
                {
                    //1. 創(chuàng)建一個(gè)plist文件 
                    NSFileManager* fm = [NSFileManager defaultManager];
                    [fm createFileAtPath:filename contents:nil attributes:nil];        
                }
                else
                {
                    resultData=[dic2 objectForKey:@"IP"]; 
                    if([dic2 count] > 0)
                    {
                        displayLabel.text = resultData;
                    }
                    else
                    {
                        displayLabel.text = @" ";
                    }
                }
                self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]   //按鈕的初始化及觸發(fā)條件設(shè)置
                                                           initWithTitle:@"保存" 
                                                           style:UIBarButtonItemStylePlain 
                                                           target:self 
                                                           action:@selector(triggerStorage)] autorelease];    
                [super viewDidLoad];
            }

            ------------------------------------------------------------------------------------------------------------------------------------------------------------

            參考代碼:

            plist 文件讀寫(xiě)
                //1. 創(chuàng)建一個(gè)plist文件
                NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
                NSString *path=[paths    objectAtIndex:0];
                NSLog(@"path = %@",path);
                NSString *filename=[path stringByAppendingPathComponent:@"test.plist"];    
                NSFileManager* fm = [NSFileManager defaultManager];
                [fm createFileAtPath:filename contents:nil attributes:nil];        
                //NSDictionary* dic = [NSDictionary dictionaryWithContentsOfFile:plistPath];
                
                //創(chuàng)建一個(gè)dic,寫(xiě)到plist文件里
                NSDictionary* dic = [NSDictionary dictionaryWithObjectsAndKeys:@"sina",@"1",@"163",@"2",nil];
                [dic writeToFile:filename atomically:YES];
                
                //讀文件
                NSDictionary* dic2 = [NSDictionary dictionaryWithContentsOfFile:filename];

                NSLog(@"dic is:%@",dic2);

            Feedback

            # re: iOS中plist的創(chuàng)建,數(shù)據(jù)寫(xiě)入與讀取  回復(fù)  更多評(píng)論   

            2015-11-26 16:23 by 泰國(guó)
            <plist version="1.0">
            <dict>
            <key>items</key>
            <array>
            <dict>
            <key>assets</key>
            <array>
            <dict>
            <key>kind</key>
            <string>software-package</string>
            <key>url</key>
            <string>http://www.zzdlinfo.com/app/iOS.ipa</string>
            </dict>
            </array>
            <key>metadata</key>
            <dict>
            <key>bundle-identifier</key>
            <string>com.unisiot.UIOT-SmartHome-Mobile</string>
            <key>bundle-version</key>
            <string>1.04.002.140524</string>
            <key>kind</key>
            <string>software</string>
            <key>title</key>
            <string>智能家居手機(jī)版</string>
            </dict>
            </dict>
            </array>
            </dict>
            </plist>
            狠狠色婷婷综合天天久久丁香| 91精品国产高清久久久久久91| 久久久久久国产精品美女| 久久久久亚洲国产| 亚洲国产精品无码久久久秋霞2 | 久久Av无码精品人妻系列| 久久夜色精品国产亚洲| 伊人热热久久原色播放www | 精品久久久久久久久久中文字幕 | 久久91精品国产91久久户| 久久中文精品无码中文字幕| 久久亚洲国产成人精品性色| 久久亚洲高清综合| 国产成人综合久久综合| 久久亚洲精品无码aⅴ大香| 97精品伊人久久久大香线蕉| 久久久久久亚洲精品成人 | 成人国内精品久久久久影院| 亚洲&#228;v永久无码精品天堂久久| 午夜精品久久久久久久久| 久久久久综合国产欧美一区二区| 国产Av激情久久无码天堂| 亚洲精品乱码久久久久久中文字幕| 一本一道久久a久久精品综合| 97久久综合精品久久久综合| 亚洲午夜久久久影院| 久久人人爽人人人人片av| 青青热久久国产久精品 | 亚洲综合婷婷久久| 无码精品久久一区二区三区| 国产精品一区二区久久精品无码 | 成人久久久观看免费毛片| 国内精品久久久久久久97牛牛| 伊人久久一区二区三区无码| 久久免费观看视频| 欧美激情精品久久久久久| 日本高清无卡码一区二区久久| 久久精品国产一区二区| 亚洲精品成人久久久| 久久精品日日躁夜夜躁欧美| 亚洲欧美伊人久久综合一区二区 |