저는 iOS/Objective C에 매우 익숙하지만 여러 언어로 여러 해 동안 프로그래밍 해왔습니다.plist를로드 할 때 배열 첨자가 정수가 아닙니다.
저희 회사는 기존 iOS 응용 프로그램을 수정했습니다. 지금 plist 파일을로드하고 그 내용으로 UITableView 채 웁니다. 내 코드를 사용하여 셀을 만드는 동안 오류가 발생하며 어떤 일이 일어나는지 잘 모르겠습니다.
여기에, 아주 간단한 내 PLIST 파일입니다
여기<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>title</key><string>Un</string>
<key>subtitle</key><string>Subtitle</string>
</dict>
<dict>
<key>title</key><string>Deux</string>
<key>subtitle</key><string>Subtitle</string>
</dict>
</array>
</plist>
내가 메모리에 PLIST 파일을로드 어디에 :
- (void)viewDidLoad {
[super viewDidLoad];
NSString *plistCatPath = [[NSBundle mainBundle] pathForResource:@"resources" ofType:@"plist"];
resources = [NSMutableArray arrayWithContentsOfFile:plistCatPath];
}
을 그리고 여기에 내가 속성에 액세스하려고 곳입니다. 이것은 분명히 새 객체 리터럴 구문을 인식하지 못하는 오래된 컴파일러를 사용하고 있기 때문에
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
int index = (int) indexPath.row;
UITableViewCell *cell =[factory cellOfKind:@"cell" forTable:tableView];
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
UILabel *lblTitle = (UILabel*)[cell viewWithTag:2];
UILabel *lblSubtitle = (UILabel*)[cell viewWithTag:3];
NSDictionary *resource = resources[index]; // incompatible types in initialization
NSString *row_title = resource[@"title"]; // array subscript is not an integer
NSString *row_subtitle = resource[@"subtitle"]; // array subscript is not an integer
[lblTitle setText: row_title];
[lblSubtitle setText: row_subtitle];
return cell;
}
최신 버전의 'clang'을 사용하고 있습니까? GCC와 오래된 Clang은이 구조를 인식하지 못합니다. –
@ H2CO3 나는 거의 긍정적이다. 기존 프로젝트의 이전 소스 코드와 10.6.8이있는 Mac에만 액세스 할 수 있기 때문에 Xcode 3.2.6을 실행하고 iOS 4.2 용으로 컴파일하고 있습니다. 나는 그것이 필요하지 않다면 이것의 일부 또는 전부를 업그레이드하는 것을 저항 해왔다. "다른 구조"(가능하다면)를 추천하거나 다른 이유로 다른 곳으로 업그레이드해야 할 필요가 있습니까? – raydowe
또 다른 구조가 있습니다. 제 답변을 참조하십시오. –