2011-02-12 171 views
0

我有這個代碼的問題。我一直在尋找解決方案,並得到以下警告:推送視圖控制器的問題

警告:(消息沒有匹配的方法簽名將假定返回'id'並接受'...'作爲參數)。

我知道可能有.h文件的問題,但我找不到在哪裏。

#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 

.m文件:

-(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 = [[QandA_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; 
} 
} 

我得到以下輸出:

2011-02-12 22:20:40.943 FamQuiz_R0_1 [6346:207] - [MainViewController setQandA_ViewController:]:無法識別的選擇器發送到實例0xa120980
2011-02-12 22:20:40.945 FamQuiz_R0_1 [6346:207] *終止應用程序由於未捕獲的異常 'NSInvalidArgumentException',原因: ' - [MainViewController setQandA_ViewController:]:無法識別的選擇發送到實例0xa120980'

回答

1

有一個簡單的錯字。你聲明一個屬性爲QandA_ViewController *qanda_ViewController,所以設置者的名字將是setQanda_ViewController,大寫字母Q,小寫字母a(只有第一個字母大寫)。

嘗試[self setQanda_ViewController:temp];或重命名您的財產。

+0

非常感謝。真的很感謝你的幫助,我現在學到了一些新的東西:-) ......經過一番研究。 – PeterK 2011-02-12 21:50:08