我有一个具有以下内容的类 HelloWorldViewController
-(void) addDate method
NSDate *myDate = [myDatePIcker dateValue];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"YYYYMMdd"];
NSLog(@"addDate date is:%@",[dateFormat stringFromDate:myDate]);
当我像这样从 IBAction 调用上述方法时......
- (IBAction)myAddDate:(id)sender {
[self addDate];
}
它按预期工作(请参阅下面的 NSLog)
2013-03-14 09:05:33.149 APPNAME[3531:303] AWAKENED in Hello 2013-03-14 16:05:33 +0000
2013-03-14 09:05:33.150 APPNAME[3531:303] AWAKENED in Hello (null)
2013-03-14 09:05:35.898 APPNAME[3531:303] addDate date is:20130314
2013-03-14 09:05:35.899 APPNAME[3531:303] addDate completed with date 20130314
但是,如果我从另一个子类 (TableViewController) 中的方法 (datePickerAction) 调用 -(void) 函数,请参见下文......
@implementation TableViewController:HelloWorldViewController
-(IBAction)datePickerAction:(id)sender{
[self addDate];
}
这是 NSLog 的输出
2013-03-14 09:08:01.719 APPNAME[3549:303] AWAKENED in Hello 2013-03-14 16:08:01 +0000
2013-03-14 09:08:01.720 APPNAME[3549:303] AWAKENED in Hello (null)
2013-03-14 09:08:03.321 APPNAME[3549:303] addDate date is:(null)
2013-03-14 09:08:03.322 APPNAME[3549:303] addDate completed with date (null)
2013-03-14 09:08:03.323 APPNAME[3549:303] addDate date is:(null)
2013-03-14 09:08:03.323 APPNAME[3549:303] addDate completed with date (null)
我是绿色的,放轻松:-)任何建议表示赞赏!
更新:我尝试实施以下解决方案。这是更新的和附加的代码。该应用程序现在不会启动......任何建议。
@implementation HelloWorldViewController;
-(id) init{
HelloWorldViewController *myHelloWorldController = [[HelloWorldViewController alloc] init];
return self;
}
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
#import "HelloWorldViewController.h"
#import "Date.h"
>
@interface TableViewController : NSTableView <NSTableViewDataSource> {
IBOutlet NSTableView *tableview;
NSMutableArray *list;}
#import "TableViewController.h"
#import "HelloWorldViewController.h"
@implementation TableViewController{
HelloWorldViewController *myHelloWorldViewController;}
- (id) init{
self = [super init];
if (self) {
list = [[NSMutableArray alloc] init];
}
return self;}
- (IBAction)datePickerAction:(id)sender{
[myHelloWorldViewController addDate];
//NSLog(@"Action Finished with date %@", myRename);}