調用選擇在AppDelegate.m,我定義從多個文件
#import "AppDelegate.h"
#import "allerta.h"
@implementation AppDelegate
@synthesize window = _window;
-(void)awakeFromNib {
// Add an observer that will respond to loginComplete
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(alerticonstatus:)
name:@"alert" object:nil];
// Post a notification to loginComplete
[[NSNotificationCenter defaultCenter] postNotificationName:@"alert" object:nil];
}
@end
我想從allerta.h調用alerticonstatus:
#import <Foundation/Foundation.h>
@interface allerta : NSObject{
}
-(void)alerticonstatus:(NSNotification *)note;
@end
allerta.m:
#import "allerta.h"
@implementation allerta
-(void)alerticonstatus:(NSNotification *)note {
NSLog(@"called alerticonstatus");
}
@end
我可以從其他文件如allerta.h中導入函數whit @selector嗎? 現在我有SIGABRT錯誤。 你能幫我嗎?謝謝。
Thanks Infog。我需要[_allerta發佈];在OSX中? – Joannes 2012-02-13 15:22:13
然後,您爲對象創建分配內存(alloc,copy,new),您需要爲對象創建釋放,而不需要該對象。您需要閱讀有關Objective-C開發的更多信息。 – alexmorhun 2012-02-13 16:06:58
你可以將'allerta * _allerta = [allerta alloc];'改成'* _allerta = [[allerta alloc] autorelease];'然後你不需要寫'[_allerta release];' – alexmorhun 2012-02-13 16:08:09