我是创建iPhone应用程序的新手,刚刚开始使用Xcode,我遇到了以下错误;我以前在模拟器和模拟器上使用过这段代码。一个iPod touch,它适用于两者,但由于某种原因,最近它不允许我从一个页面转到另一个页面而不给我“SIGABRT”错误。
基本上在我的应用程序中,我需要多次从一个页面转到另一个页面但是它不起作用....有人可以帮忙吗?
这是它似乎不满意的代码(它符合并成功构建):
1 #import <UIKit/UIKit.h>
2
3 int main(int argc, char *argv[])
4 {
5 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
6 int retVal = UIApplicationMain(argc, argv, nil, nil);
7 [pool release];
8 return retVal;
9 }
它停在 int retVal 行(第6行)上。
调试时出现错误:
2011-09-09 15:33:59.029 TruckFile [1072:b603] * 由于未捕获的异常'NSUnknownKeyException'而终止应用程序,原因:'[&lt; UIApplication 0x6044600&gt; setValue:forUndefinedKey:]:此类不是密钥窗口的密钥值编码兼容。'
有人可以帮我这个吗?
========================================
代码文件:
========================================
#import <UIKit/UIKit.h>
#import "ViewTwoController.h"
#import "TruckFileAppDelegate.h"
@interface TruckFileAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
ViewTwoController *viewTwoContoller;
UINavigationController *navigationController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext;
@property (nonatomic, retain, readonly) NSManagedObjectModel *managedObjectModel;
@property (nonatomic, retain, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator;
@property (nonatomic, retain) ViewTwoController *viewTwoController;
-(IBAction)switchPage:(id)sender;
@end
=============================================== =
#import "TruckFileAppDelegate.h"
#import "ViewTwoController.h"
@implementation TruckFileAppDelegate
@synthesize window;
@synthesize navigationController;
@synthesize managedObjectContext = __managedObjectContext;
@synthesize managedObjectModel = __managedObjectModel;
@synthesize persistentStoreCoordinator = __persistentStoreCoordinator;
@synthesize viewTwoController;
-(IBAction)switchPage:(id)sender
{
if(self.viewTwoController == nil)
{
ViewTwoController *viewTwo = [[ViewTwoController alloc]
initWithNibName:@"ViewTwoController" bundle:[NSBundle mainBundle]];
self.viewTwoController = viewTwo;
[viewTwo release];
}
[self.navigationController pushViewController:self.viewTwoController animated:YES];
}
- (void)dealloc {
[navigationController release];
[window release];
[super dealloc];
}
@end
====================================
#import <UIKit/UIKit.h>
@interface ViewTwoController : UIViewController {
}
@end
=====================================
#import "ViewTwoController.h"
@implementation ViewTwoController
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
// Release anything that's not essential, such as cached data
}
- (void)dealloc {
[super dealloc];
}
@end
答案 0 :(得分:1)
mainWindow.xib正在尝试将它的UIWindow实例与你的UIApplicationDelegate连接起来,但它找不到它(这就是为什么它抱怨它无法设置UNDEFINED键的值)。
检查你的UIApplicationDelegate类有一个UIWindow iVar,它的.h属性,并且在.m中正确合成。
修改强>
谁在switchPage:
上调用方法UIApplication
?如果你是,那你就是在错误的对象上调用它。而不是做
[[UIApplication sharedApplication] switchPage:xxx];
你应该这样做:
[[[UIApplication sharedApplication] delegate] switchPage:xxx];
由于方法switchPage:
是在UIApplicationDelegate
类中定义的。
答案 1 :(得分:0)
您的代码在
处失败 [UIApplication switchPage:]:
答案 2 :(得分:0)
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIApplication switchPage:]: unrecognized selector sent to instance 0x600beb0'
这意味着在您的switchPage方法中,您正在对未知标识符执行操作,可能会检查对象标识符名称,并检查您是否已在.h文件中初始化它。