• <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ā)條件設置
                                                           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ù)寫入與讀取  回復  更多評論   

            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>智能家居手機版</string>
            </dict>
            </dict>
            </array>
            </dict>
            </plist>
            久久青青草视频| 国产福利电影一区二区三区久久老子无码午夜伦不 | 久久棈精品久久久久久噜噜| 人人狠狠综合久久88成人| 色综合久久久久综合体桃花网| 国产A三级久久精品| 狠狠色婷婷综合天天久久丁香| 一本大道久久a久久精品综合| 色播久久人人爽人人爽人人片aV| 久久久久久久精品成人热色戒| 久久久综合九色合综国产| 欧美一级久久久久久久大片| 久久ZYZ资源站无码中文动漫 | 欧洲人妻丰满av无码久久不卡| 久久久精品国产sm调教网站| 91亚洲国产成人久久精品网址| 亚洲国产综合久久天堂 | 久久99精品免费一区二区| 97久久国产综合精品女不卡| 久久精品国产亚洲一区二区| 人妻无码精品久久亚瑟影视 | 狠狠久久亚洲欧美专区| 伊人色综合久久天天人守人婷| 久久ww精品w免费人成| 欧美久久久久久| 久久电影网| 久久久久久综合一区中文字幕| 伊人久久大香线蕉av不卡| 久久久久18| 四虎国产永久免费久久| 精品精品国产自在久久高清| 亚洲AV无码久久精品狠狠爱浪潮 | 亚洲愉拍99热成人精品热久久| 久久久久国产精品三级网| 久久精品视频免费| 久久精品男人影院| 亚洲综合精品香蕉久久网97| 久久婷婷久久一区二区三区| 久久久久久久综合日本亚洲| 久久精品国产一区| 久久精品视频91|