推送视图控制器的问题
Posted
技术标签:
【中文标题】推送视图控制器的问题【英文标题】:Problem pushing a viewcontroller 【发布时间】:2011-02-12 21:35:23 【问题描述】:我对这段代码有疑问。我一直在寻找解决方案并收到以下警告:
警告:(没有匹配方法签名的消息将被假定返回“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
声明了一个属性,因此setter 的名称将是setQanda_ViewController
,大写Q,但小写a(只有第一个字母大写)。
尝试[self setQanda_ViewController:temp];
或重命名您的资源。
【讨论】:
非常感谢。非常感谢您的帮助,我现在学到了一些新东西:-) ...经过大量研究。以上是关于推送视图控制器的问题的主要内容,如果未能解决你的问题,请参考以下文章