• <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>
            久久午夜夜伦鲁鲁片免费无码影视| 国产午夜免费高清久久影院| 亚洲av日韩精品久久久久久a| 久久综合九色欧美综合狠狠| 99久久免费国产精品| 国产午夜精品理论片久久影视| 国产精品99精品久久免费| 久久精品无码专区免费青青| 久久综合狠狠综合久久综合88| 午夜精品久久久久久久| 久久综合九色综合网站| 97久久超碰国产精品2021| 99久久无码一区人妻a黑| 精品久久久久久亚洲| 久久er国产精品免费观看2| 国产精品久久国产精品99盘| 91精品国产91久久久久久蜜臀| 精品久久人人爽天天玩人人妻| 久久精品一区二区三区中文字幕| 久久精品免费网站网| 久久久久亚洲精品中文字幕| 偷窥少妇久久久久久久久| 久久久久久夜精品精品免费啦| 国产91色综合久久免费分享| 久久精品国产一区二区| 亚洲中文字幕久久精品无码喷水| 精品久久久久久亚洲精品| 国产精品伊人久久伊人电影| 中文字幕精品久久久久人妻| 久久人人爽爽爽人久久久| 精品无码久久久久久久动漫| 久久亚洲AV无码精品色午夜| 国产精品久久久久久久| 亚洲综合久久久| 亚洲成色999久久网站| 亚洲中文字幕无码久久2020| 99国内精品久久久久久久| 亚洲精品乱码久久久久久自慰| 精品999久久久久久中文字幕| 亚洲国产精品无码久久青草| 亚洲国产精品久久|