• <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)建一個(gè)test.plist文件,textInput作為輸入,displayLabel作為顯示,有一個(gè)按鈕來觸發(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,寫到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)建一個(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 文件讀寫
                //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,寫到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>
            久久久久亚洲Av无码专| 久久婷婷是五月综合色狠狠| 99久久精品费精品国产一区二区| 国产精品99久久免费观看| 久久综合久久综合九色| 久久国内免费视频| 久久国产精品77777| 久久久亚洲精品蜜桃臀| 久久久久亚洲AV片无码下载蜜桃| 婷婷伊人久久大香线蕉AV | 久久成人国产精品免费软件| 久久久久亚洲AV片无码下载蜜桃| 国产激情久久久久影院| 亚洲精品白浆高清久久久久久| 久久99精品综合国产首页| 久久毛片一区二区| 久久av高潮av无码av喷吹| 久久国产精品无码一区二区三区 | 久久久无码精品午夜| 国产精品久久午夜夜伦鲁鲁| 亚洲一区精品伊人久久伊人| 久久免费国产精品一区二区| 亚洲AV乱码久久精品蜜桃| 人妻少妇精品久久| 精品99久久aaa一级毛片| 久久久无码精品亚洲日韩蜜臀浪潮| 岛国搬运www久久| 日本久久久久亚洲中字幕| 久久91精品国产91久| 久久无码精品一区二区三区| 91精品久久久久久无码| 久久久久免费精品国产| 99久久国语露脸精品国产| 性欧美丰满熟妇XXXX性久久久| 一级女性全黄久久生活片免费| 国产激情久久久久影院老熟女免费| 97久久精品人妻人人搡人人玩| 国产精品一区二区久久国产| 人妻无码久久一区二区三区免费| 伊人久久大香线蕉av一区| 亚洲女久久久噜噜噜熟女|