我正在尝试将我之前制作的tableview实现到我刚刚创建的基于tabview的新应用程序中,并且所有构建和编译,但是当我选择导入 tableview的选项卡时,它会崩溃出现以下错误:
[Session started at 2011-04-23 00:55:14 +0200.]
2011-04-23 00:55:16.361 EXOtab[1123:207] -[EXOtabAppDelegate larms]: unrecognized selector sent to instance 0x5f2b4e0
对象larms在我的头文件中定义,用于解析我的tableview的数据。
#import <UIKit/UIKit.h>
@interface XMLAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UINavigationController *navigationController;
NSMutableArray *larms;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (nonatomic, retain) NSMutableArray *larms;
- (void)loadXML;
@end
我不知道我是否错过了从我的tableview的数据模型中输入我的任何标题文件,或者在调用它时我是否有错误的参考。当然,如果我在室外使用它作为tableview应用程序而不是在我的标签栏应用程序中,它可以正常工作。
我的ViewControllers:
#import "EXOtabAppDelegate.h"
#import "EXOtabViewController.h"
#import "users.h"
#import "info.h"
#import "RootViewController.h" // My Tableview
@implementation EXOtabAppDelegate
@synthesize window;
@synthesize viewController;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UITabBarController *tabBarController = [[UITabBarController alloc] init];
UIViewController *vc1 = [[info alloc] init];
UIViewController *vc2 = [[users alloc] init];
UIViewController *vc3 = [[RootViewController alloc] init];
NSArray *viewControllers = [NSArray arrayWithObjects:vc1, vc2, vc3, nil];
[vc1 release];
[vc2 release];
[vc3 release];
[tabBarController setViewControllers:viewControllers];
[window setRootViewController:tabBarController];
[tabBarController release];
[window makeKeyAndVisible];
return YES;
}
任何想法?如果您需要查看更多代码,请告诉我
// reg:mandelmassa
我还有一些代码可以显示:
//RootViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
if (_refreshHeaderView == nil) {
EGORefreshTableHeaderView *view = [[EGORefreshTableHeaderView alloc] initWithFrame:CGRectMake(0.0f, 0.0f - self.tableView.bounds.size.height, self.view.frame.size.width, self.tableView.bounds.size.height)];
view.delegate = self;
[self.tableView addSubview:view];
_refreshHeaderView = view;
[view release];
}
// update the last update date
[_refreshHeaderView refreshLastUpdatedDate];
//this is where the app crashes!
appDelegate = (XMLAppDelegate *)[[UIApplication sharedApplication] delegate];
self.title = @"Larm";
}
//RootViewController.h
#import <UIKit/UIKit.h>
#import "EGORefreshTableHeaderView.h"
@class XMLAppDelegate, LarmDetail;
@interface RootViewController : UITableViewController <EGORefreshTableHeaderDelegate, UITableViewDelegate, UITableViewDataSource>{
XMLAppDelegate *appDelegate;
LarmDetail *ldvController;
EGORefreshTableHeaderView *_refreshHeaderView;
BOOL _reloading;
}
- (void)reloadTableViewDataSource;
- (void)doneLoadingTableViewData;
@end
//XMLAppDelegate.h
#import <UIKit/UIKit.h>
@interface XMLAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UINavigationController *navigationController;
NSMutableArray *larms;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (nonatomic, retain) NSMutableArray *larms;
- (void)loadXML;
@end
//XMLAppDelegate.m
#import "XMLAppDelegate.h"
#import "RootViewController.h"
#import "XMLParser.h"
@implementation XMLAppDelegate
@synthesize window;
@synthesize navigationController, larms;
-(void)applicationDidFinishLaunching:(UIApplication *)application {
[self loadXML]; //egen function för att ladda data
// Configure and show the window
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
}
- (void)loadXML{
NSURL *url = [[NSURL alloc] initWithString:@"http://192.168.1.90/EXOxml.php?nAlarms=2"];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL: url];
//Initialize the delegate.
XMLParser *parser = [[XMLParser alloc] initXMLParser];
//Set delegate
[xmlParser setDelegate:parser];
//Start parsing the XML file.
BOOL success = [xmlParser parse];
if(success)
NSLog(@"Data loaded");
else
NSLog(@"Data fail!!!");
}
- (void)applicationWillTerminate:(UIApplication *)application {
// Save data if appropriate
}
- (void)dealloc {
[larms release];
[navigationController release];
[window release];
[super dealloc];
}
@end
任何人都可以看到我的应用为什么会出错?
reg Mandel
(XMLAppdelegate)
#import <UIKit/UIKit.h>
@interface XMLAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UINavigationController *navigationController;
NSMutableArray *larms;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (nonatomic, retain) NSMutableArray *larms;
- (void)loadXML;
@end
(XMLAppDelegate.m)
#import "XMLAppDelegate.h"
#import "RootViewController.h"
#import "XMLParser.h"
@implementation XMLAppDelegate
@synthesize window;
@synthesize navigationController, larms;
-(void)applicationDidFinishLaunching:(UIApplication *)application {
[self loadXML]; own function to load data
// Configure and show the window
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
}
- (void)loadXML{
NSURL *url = [[NSURL alloc] initWithString:@"http://xxx.xxx.xxx.xxx/somefile.php?nAlarms=2"];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL: url];
//Initialize the delegate.
XMLParser *parser = [[XMLParser alloc] initXMLParser];
//Set delegate
[xmlParser setDelegate:parser];
//Start parsing the XML file.
BOOL success = [xmlParser parse];
if(success)
NSLog(@"No Errors");
else
NSLog(@"Error Error Error!!!");
}
- (void)applicationWillTerminate:(UIApplication *)application {
// Save data if appropriate
}
- (void)dealloc {
[larms release];
[navigationController release];
[window release];
[super dealloc];
}
@end
答案 0 :(得分:0)
您的班级XMLAppDelegate
和EXOtabAppDelegate
都实施了UIApplicationDelegate
协议。 每个应用程序不应包含多个UIApplicationDelegate。
您的应用程序委托在主nib文件中设置(通常为“MainWindow.xib”)。您应该已将文件所有者(UIApplication
对象)的“委托”出口连接到.xib文件中的UIApplicationDelegate
对象,并且UIApplicationDelegate
的类是设置为您应用的UIApplicationDelegate
子类,XMLAppDelegate
或EXOtabAppDelegate
。
由于您的XMLAppDelegate
具有larms
属性且EXOtabAppDelegate
没有属性,我猜您的应用程序委托实际上已设置为主nib文件中的EXOtabAppDelegate
。
如果EXOtabAppDelegate
是您的申请代表,则无法执行此操作:
appDelegate = (XMLAppDelegate *)[[UIApplication sharedApplication] delegate];