가장 쉬운은 다음 NSArray
및 NSDictionary
형식의 데이터에서 plist
파일을 만드는 것입니다 :
<?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">
<array>
<dict>
<key>Name 1</key>
<string>Description 1</string>
</dict>
<dict>
<key>Name 2</key>
<string>Description 2</string>
</dict>
</array>
</plist>
응용 프로그램이 파일을 추가합니다. 당신이 그것을 액세스 할 때, 당신은 지금 당신이
NSArray
당신이 당신의
UITableView
에 필요한 정보를 가지고 각각의
NSDictionaries
을 포함해야
NSString *path=[[NSBundle mainBundle] pathForResource:@"MyList" ofType:@"plist"];
NSArray *array =[NSArray arrayWithContentsOfFile:path];OfFile:path];
하여이 작업을 수행.
이제이 배열을 사용하여 UITableView
을 채우면됩니다. 다음 두 가지 방법을 구현하여이 작업을 수행하십시오.
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section
{
return [array count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// Create your cells
NSDictionary *dict = [array objectAtIndex:indexPath.row];
// use the key and description however you like in your cell
}
감사합니다. –