我正在编写iPad应用程序并创建了DatePickerView并从UIPopoverController调用它,如下所示:
DatePickerView *dt = [[DatePickerView alloc] initWithNibName:nil bundle:nil];
popover = [[UIPopoverController alloc] initWithContentViewController:dt];
popover.delegate = self;
[dt release];
self.popoverController = popover;
[popover release];
CGRect popoverRect = [self.view convertRect:[sender frame] fromView:[sender superview]];
popoverRect.size.width = MIN(popoverRect.size.width, 100);
[self.popoverController presentPopoverFromRect:popoverRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
在DatePickerView中,当选择“完成”按钮时,我有以下代码,这基本上是通过使用appdelegate将格式化程序的选定日期发送回主UI:
.H 我
BOutlet UIDatePicker *dtPicker;
-(IBAction) btnSelectClicked:(UIButton *)sender
{
MachineDetailsView *appDelegate;
appDelegate = (MachineDetailsView *)[[UIApplication sharedApplication] delegate];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MM/dd/YYYY"];
NSDate *dt = [dtPicker date];
appDelegate.backPickerStartDate = [formatter stringFromDate:dt];
}
在MachineDetailsView中的我声明了backPickerStartDate,如下所示:
.h:文件详情
NSString *backPickerStartDate;
UIPopoverController *popoverController;
UIPopoverController *popover;
....
@property(nonatomic, retain) NSString *backPickerStartDate;
....
.m:文件详情
@synthesize backPickerStartDate;
当我点击DatePickerView的“完成”按钮
时,我收到以下错误2011-03-23 11:46:59.813 iMobile[22492:40b] -[iMobileAppDelegate setBackPickerStartDate:]: unrecognized selector sent to instance 0x8a3dc00
2011-03-23 11:46:59.816 iMobile[22492:40b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[iMobileAppDelegate setBackPickerStartDate:]: unrecognized selector sent to instance 0x8a3dc00'
*** Call stack at first throw:
(
0 CoreFoundation 0x00df9be9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f4e5c2 objc_exception_throw + 47
2 CoreFoundation 0x00dfb6fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00d6b366 ___forwarding___ + 966
4 CoreFoundation 0x00d6af22 _CF_forwarding_prep_0 + 50
5 UIKit 0x00302a6e -[UIApplication sendAction:to:from:forEvent:] + 119
6 UIKit 0x003911b5 -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x00393647 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
8 UIKit 0x003921f4 -[UIControl touchesEnded:withEvent:] + 458
9 UIKit 0x003270d1 -[UIWindow _sendTouchesForEvent:] + 567
10 UIKit 0x0030837a -[UIApplication sendEvent:] + 447
11 UIKit 0x0030d732 _UIApplicationHandleEvent + 7576
12 GraphicsServices 0x0172fa36 PurpleEventCallback + 1550
13 CoreFoundation 0x00ddb064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
14 CoreFoundation 0x00d3b6f7 __CFRunLoopDoSource1 + 215
15 CoreFoundation 0x00d38983 __CFRunLoopRun + 979
16 CoreFoundation 0x00d38240 CFRunLoopRunSpecific + 208
17 CoreFoundation 0x00d38161 CFRunLoopRunInMode + 97
18 GraphicsServices 0x0172e268 GSEventRunModal + 217
19 GraphicsServices 0x0172e32d GSEventRun + 115
20 UIKit 0x0031142e UIApplicationMain + 1160
21 iG2Mobile 0x000022f2 main + 84
22 iG2Mobile 0x00002295 start + 53
)
terminate called after throwing an instance of 'NSException'
Program received signal: “SIGABRT”.
任何帮助都非常受欢迎。如果需要进一步的细节,请告诉我。
我还在下面将setter方法添加到MachineDetailsView中,但仍然没有用:
-(void)setBackPickerStartDate:(NSString *)newBackPickerStartDate
{
if (backPickerStartDate != newBackPickerStartDate) {
backPickerStartDate = newBackPickerStartDate;
}
}
非常感谢
答案 0 :(得分:1)
您已声明已声明并合成backPickerStartDate
类中的MachineDetailsView
属性,但您在iMobileAppDelegate
<{1}}中的btnSelectClicked:
实例上调用它/ p>
appDelegate.backPickerStartDate = [formatter stringFromDate:dt];
上面几行,你有这个:
MachineDetailsView *appDelegate;
appDelegate = (MachineDetailsView *)[[UIApplication sharedApplication] delegate];
这是错误的,因为您将指向应用委托的指针转换为指向MachineDetailsView的指针。这不会让你的app委托对象神奇地变成MachineDetailsView对象。你需要的是一个getter方法或属性,它返回你的MachineDetailsView对象(或者找到另一种方法来访问它)。
答案 1 :(得分:0)
[iMobileAppDelegate setBackPickerStartDate:]: unrecognized selector sent to instance
根据上面的例外情况,您需要在app委托中声明backPickerStartDate。