iOS 응용 프로그램 에서 사용자 가 설정 한 plist 파일 의 생 성 및 읽 기 및 쓰기 튜 토리 얼 을 저장 합 니 다.
Plist 파일 은 보통 사용자 설정 을 저장 하 는 데 사용 되 며,묶 인 정 보 를 저장 하 는 데 도 사용 된다.
우 리 는 plist 파일 의 읽 기와 쓰 기 를 배 울 항목 을 만 들 었 다.
1.프로젝트 Plistdemo 만 들 기
프로젝트 생 성 후 프로젝트 에 대응 하 는 plist 파일 을 찾 을 수 있 습 니 다.다음 그림 과 같이 엽 니 다.
편집기 에 표 와 유사 한 형식 을 표시 합 니 다.plist 에서 오른쪽 단 추 를 누 르 고 소스 코드 로 열 면 plist 파일 의 xml 형식 을 볼 수 있 습 니 다.
2.plist 파일 을 만 듭 니 다.
command+N 단축 키 로 만 들 거나 File―>New―>New File 을 누 르 고 Mac OS X 의 Property List 를 선택 하 십시오.
파일 이름 은 custom Info 이 고 Group 은 Supporting Files 를 선택 합 니 다.
3.새로 만 든 customeInfo.plist 를 누 르 면 데 이 터 를 추가 합 니 다.다음 그림:
Type 항목 의 종 류 는 Dictionary 를 선택 하고 Source Code 로 열 어 다음 과 같이 표시 합 니 다.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Student</key>
<dict>
<key>Name</key>
<string>Yang</string>
<key>Sex</key>
<string>Male</string>
<key>Num</key>
<string>SX_010</string>
</dict>
<key>Mentor</key>
<dict>
<key>Name</key>
<string>Gu</string>
<key>Sex</key>
<string>Male</string>
</dict>
</dict>
</plist>
4.보기 에 컨트롤 추가:BIDViewController.xib 를 누 르 면 IB 를 열 고 몇 개의 컨트롤 을 끌 어 올 리 고 레이아웃 을 설정 합 니 다.다음 그림:
위의 그림 에서 모든 컨트롤 은 Label 이 고 글꼴 크기 를 설정 합 니 다.
5.다음은 맵 입 니 다.다섯 개의 회색 레이 블 을 모두 BIDViewController.h 파일 에 투사 합 니 다.유형 은 모두 Outlet 이 고 이름 은 stuName,stuSex,stuNum,mtName,mtSex 입 니 다.
6.BIDViewController.m 을 누 르 면 viewdLoad 방법 중의[슈퍼 viewdLoad]에 다음 코드 를 추가 합 니 다.
// studentInfo.plist
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"customInfo" ofType:@"plist"];
NSDictionary *dictionary = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
//
NSDictionary *tmpInfo = [dictionary objectForKey: @"Student"];
self.stuName.text = [NSString stringWithFormat:@"%@", [tmpInfo objectForKey: @"Name"]];
self.stuSex.text = [NSString stringWithFormat:@"%@", [tmpInfo objectForKey: @"Sex"]];
self.stuNum.text = [NSString stringWithFormat:@"%@", [tmpInfo objectForKey: @"Num"]];
//
tmpInfo = [dictionary objectForKey: @"Mentor"];
self.mtName.text = [NSString stringWithFormat:@"%@", [tmpInfo objectForKey: @"Name"]];
self.mtSex.text = [NSString stringWithFormat:@"%@", [tmpInfo objectForKey: @"Sex"]];
7.실행,효과 보기:이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
View의 레이아웃 방법을 AutoLayout에서 따뜻한 손 계산으로 하면 성능이 9.26배로 된 이야기이 기사는 의 15 일째 기사입니다. 어제는 에서 이었습니다. 손 계산을 권하는 의도는 없고, 특수한 상황하에서 계측한 내용입니다 화면 높이의 10 배 정도의 contentView가있는 UIScrollView 레이아...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.