그래, 당신이 경로를 인쇄하고,없는 항목을 배열. 에 대한 질문에 대한 응답으로
-(IBAction) buttonPress {
NSString *path = [[NSBundle mainBundle] pathForResource:@"messages" ofType:@"plist"];
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
[myMessage setText:[dict objectForKey:@"text"]];
}
- 특정 텍스트를 호출 할 수 있도록 당신이 딕셔너리가 아닌 배열을 포함하여 PLIST을 변경할 수 있습니다
[myMessage setText:path];
또한
[myMessage setText:[array objectAtIndex:x]; //x = whatever index in the array contains your string.
에 변경 arc4random. switch 문을 만들 수 있도록
은 열거 만들기 - 당신이 BTW 0과 1 개를-번호를 얻을 수 있도록
typedef enum {
MESSAGE1,
MESSAGE2,
MESSAGE3
} messageIDs;
다음 임의의 정수를 생성하고 X하여 MOD. (우리가 열거 내부 3 일, X = 3이이 경우, 이후)
int randomValue = arc4random() % 3;
는 switch 문
switch (randomValue) {
case MESSAGE1:
[myMessage setText:[dict objectForKey:@"message1"]]; //or [myMessage setText:[array objectAtIndex:MESSAGE1]]
break;
case MESSAGE2:
[myMessage setText:[dict objectForKey:@"message2"]];
break;
case MESSAGE3:
[myMessage setText:[dict objectForKey:@"message3"]];
break;
default:
break;
}
이 작품 희망이 임의 INT를 사용합니다. 나는 전에 이것을 시도한 것을 havent ...
나는 또한 경고 메시지를 받는다 : "unused variable array" – hanumanDev
어레이가 사용되지 않는다는 경고를 받는다는 것에 놀라 는가? 코드를 보면 실제로 어디서나 사용할 수 있습니까? – Felixyz