Problem pushing a viewcontroller
I have a problem with this code. I have been looking for the solution and get the following warning:
warning: (Messages without a matching method signature will be assumed to return 'id' and accept '...' as arguments.).
I know that there probably is a problem with the .h file but i cannot find where.
#import <UIKit/UIKit.h>
@class NewGameViewController;
@class AccessCurrentGameData;
@class QandA_ViewController;
enum {
kTagNewGame = 1,
kTagContinueGame = 2,
};
@interface MainViewController : UIViewController <UIAlertViewDelegate> {
IBOutlet NewGameViewController *newGameViewController;
IBOutlet QandA_ViewController *qanda_ViewController;
UIAlertView *continueExistingGame_alert;
UIAlertView *zeroGameFile_alert;
NSString *title_txt;
NSString *message_txt;
NSString *cancelButton_txt;
NSString *otherButton_txt;
UIAlertView *myAlert;
}
@property (nonatomic, retain) IBOutlet NewGameViewController *newGameViewController;
@property (nonatomic, retain) IBOutlet QandA_ViewController *qanda_ViewController;
@property (nonatomic, retain) UIAlertView *myAlert;
-(IBAction)continueGame_button:(id)sender;
-(IBAction)newGame_button:(id)sender;
@end
The .m file:
-(IBAction)continueGame_button:(id)sender {
//=====CHECK IF THERE IS AN ON-GOING GAME, IF SO CONTINUE=====//
AccessCurrentGameData *isThereAnOngoingGameFunction = [AccessCurrentGameData new];
BOOL ongoingGame = [isThereAnOngoingGameFunction checkIfGameOngoing];
[isThereAnOngoingGameFunction release];
NSLog(@"+ + +continueGame_button+ + +");
NSLog(@"ongoingGame = %@\n", (ongoingGame ? @"YES" : @"NO"));
//
if (ongoingGame == YES) {
NSLog(@"+++++++++ ONGOING GAME +++++++++");
myAlert = [[UIAlertView alloc]
initWithTitle:@"Fortsätta spel"
message:@"Det finns ett aktivt spel, klicka Spela eller Tillbaka"
delegate:self
cancelButtonTitle:@"Tillbaka"
otherButtonTitles:@"Spela", nil];
myAlert.tag=kTagContinueGame;
[myAlert show];
[myAlert release];
}
}
// Load new game screen
-(IBAction)newGame_button:(id)sender {
myAlert = [[UIAlertView alloc]
initWithTitle:@"Varning"
message:@"Om du går vidare kommer pågående spel stoppas och nollställas!"
delegate:self
cancelButtonTitle:@"Tillbaka"
otherButtonTitles:@"Fortsätt", nil];
myAlert.tag=kTagNewGame;
[myAlert show];
[myAlert release];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
switch(myAlert.tag ) {
case kTagContinueGame:
NSLog(@"kTagContinueGame");
NSMutableArray *continueGameArray = [[NSMutableArray alloc] initWithCapacity:0];
AccessCurrentGameData *getCurrentGameInfo = [AccessCurrentGameData new];
continueGameArray = [getCurrentGameInfo continueTheCurrentGame];
[getCurrentGameInfo release];
NSLog(@"continueGameArray %@", continueGameArray);
[continueGameArray release];
QandA_ViewController * temp = [[Qa开发者_JS百科ndA_ViewController alloc] init];
[self setQandA_ViewController:temp]; //>>>>>HERE IS THE PROBLEM
[temp release];
[[self navigationController] pushViewController:qanda_ViewController animated:YES];
break;
case kTagNewGame:
NSLog(@"kTagNewGame");
AccessCurrentGameData *zeroCurrentGameFileFunction = [AccessCurrentGameData new];
[zeroCurrentGameFileFunction firstCreationOrRestoreOfGameDataFile];
[zeroCurrentGameFileFunction release];
NewGameViewController * temp2 = [[NewGameViewController alloc] init];
[self setNewGameViewController:temp2];
[temp2 release];
[[self navigationController] pushViewController:newGameViewController animated:YES];
break;
default:
break;
}
}
I get the following output:
2011-02-12 22:20:40.943 FamQuiz_R0_1[6346:207] -[MainViewController setQandA_ViewController:]: unrecognized selector sent to instance 0xa120980
2011-02-12 22:20:40.945 FamQuiz_R0_1[6346:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MainViewController setQandA_ViewController:]: unrecognized selector sent to instance 0xa120980'
There's a simple typo. You declared a property for QandA_ViewController *qanda_ViewController
, so the setter's name will be setQanda_ViewController
with a capital Q, but a lowercase a (only the first letter is capitalized).
Try [self setQanda_ViewController:temp];
or renaming your property.
精彩评论