프로그래밍 초보자입니다. 이 모든 문제가 무엇인지 알아내는 데 어려움을 겪고 있습니다. 메시지에 표시된 텍스트를 무작위로 추출하려고한다는 경고보기입니다. 목표 C에 대한 무작위 화 경고보기 텍스트
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Hello"
message:self.YouWin.text
delegate:self
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
당신은
YouWin
에 저장된 텍스트 값이 필요하지만, 당신은 YouWin 개체 자체를 통과 :
-(void)alert:(id)sender{
int randomNumber;
randomNumber = (randomNumber() %3 + 1);
NSLog(@"%i", randomNumber);
if (randomNumber == 1) {
self.YouWin.text = [NSString stringWithFormat:@"You Win"];
}
else if (randomNumber == 2) {
self.YouWin.text = [NSString stringWithFormat:@"You Lose"];
}
else if (randomNumber == 3) {
self.YouWin.text = [NSString stringWithFormat:@"Tie"];
}
NSLog(@"%@",YouWin);
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Hello" message:[NSString stringWithFormat:@"%@",YouWin] delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
[alert show];
button.hidden = YES;
그리고 문제는 ... –
여기'message : [NSString stringWithFormat : @ "% @", YouWin]' –
Anoop이 답을 가지고 있습니다. 당신이 여기서하는 것처럼 stringWithFormat을 사용하지 말라. [NSString stringWithFormat : @ "You Win"];'. '@ "You Win"을 단순히 사용하는 것이 더 좋을 것입니다. – sosborn