Для начала, я очень плохо знаком с Objective-C, поэтому, пожалуйста, будьте конкретны. У меня были те же 2 ошибки в течение некоторого времени, я делаю приложение в XCode, которое позволяет вам вставить свое имя, затем случайным образом выбирает число, и к каждому числу прикрепляется предложение, которое будет содержать ваше имя в конце. После условных выражений у меня продолжает появляться та же ошибка, когда текстовое поле должно возвращаться. Вот часть моего кода:
@implementation MyViewController
@synthesize textField;
@synthesize label;
@synthesize string;
- (IBAction)changeGreeting:(id)sender {
self.string = textField.text;
// Allows the user to input their name and what happens if they don't put anything
- (IBAction)changeGreeting:(id)sender {
self.string = textField.text;
NSString *nameString = string;
if ([nameString length] == 0) {
nameString = @"no name";
}
// Defines a random variable between 0 and 5 and says what happens when each is selected
int r = arc4random() % 6;
if (r == 0) {
label.text = [[NSString alloc] initWithFormat:@"You will become employee of the month... at McDonalds, %@!", nameString];
}
else if (r == 1) {
label.text = [[NSString alloc] initWithFormat:@"I wouldn't call yours a future, more of a dissapointment, %@!", nameString];
}
else if (r == 2) {
label.text = [[NSString alloc] initWithFormat:@"I hope you like your parents' couch because that is the bulk of your future, %@!", nameString];
}
else if (r == 3) {
label.text = [[NSString alloc] initWithFormat:@"Your future entails a jail cell, bad choices, and a toilet you'd never want to sit on, %@!", nameString];
}
else if (r == 4) {
label.text = [[NSString alloc] initWithFormat:@"You will write a famous book about how bad this app is, %@!", nameString];
}
else if (r == 5) {
label.text = [[NSString alloc] initWithFormat:@"Your future involves cats, and lots of them, %@!", nameString];
}
}
// Returns the text field
- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
if (theTextField == textField) {
[textField resignFirstResponder];
}
return YES;
}
- (void)dealloc {
[textField release];
[label release];
[string release];
[super dealloc];
}
@end
Мои ошибки в том, что changeGreeting не объявлено, есть ожидаемое; перед: и есть ожидаемое объявление в конце ввода.