• <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++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

            功能創(chuàng)建一個test.plist文件,textInput作為輸入,displayLabel作為顯示,有一個按鈕來觸發(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)建一個dic,寫到plist文件里
                NSDictionary* dic = [NSDictionary dictionaryWithObjectsAndKeys:displayLabel.text,@"IP",nil]; //寫入數(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)建一個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 文件讀寫
                //1. 創(chuàng)建一個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)建一個dic,寫到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ù)寫入與讀取  回復(fù)  更多評論   

            2015-11-26 16:23 by 泰國
            <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精品国产综合久久香蕉| 久久久久免费精品国产| 久久久久婷婷| 久久久久亚洲AV综合波多野结衣| 国产99久久精品一区二区| 精品久久久久久无码专区不卡 | 久久天堂电影网| 久久国产一区二区| 精品国产福利久久久| 中文字幕成人精品久久不卡| 99久久国产主播综合精品 | 久久久久免费视频| 午夜精品久久久久9999高清| 久久婷婷五月综合色99啪ak| 久久成人小视频| 亚洲av成人无码久久精品 | 一本久久综合亚洲鲁鲁五月天亚洲欧美一区二区 | 久久妇女高潮几次MBA| 7777久久久国产精品消防器材| 久久久久久久女国产乱让韩 | 久久精品国产日本波多野结衣| 久久久久久久波多野结衣高潮| 99久久夜色精品国产网站| 久久国产欧美日韩精品| 99久久人人爽亚洲精品美女| 久久久久久无码国产精品中文字幕 | 久久精品国产半推半就| 久久久久久无码国产精品中文字幕| 久久99国产精品久久99小说| 国内精品久久久人妻中文字幕| 国产伊人久久| 日日躁夜夜躁狠狠久久AV| 久久国产精品成人免费| 香蕉久久久久久狠狠色| 久久国产精品成人片免费| 人妻精品久久久久中文字幕| 精品人妻久久久久久888| 亚州日韩精品专区久久久| 大伊人青草狠狠久久|