我已經創建了一個按鈕並在運行時添加了其操作。整個視圖在運行時創建。 在點擊時調用動作saveUserProfileSetting
會導致應用程序崩潰"NSInvalidArgument: Unrecornized selector sent to a instance
。當代碼出現在 其他課程中時,它工作正常。我試圖爲它創建一個新類,它崩潰了。按鈕上的應用程序崩潰單擊操作iOS
@interface LASplashViewer : NSObject
+(void) showSplashScreen;
+(void) dismissSplashScreen;
@end
(void) showSplashScreen
{
UIView *mainScreen = [[[UIApplication sharedApplication]delegate]window];
UIView *windowBlocker = [[UIView alloc]initWithFrame:mainScreen.frame];
windowBlocker.tag = 999;
windowBlocker.backgroundColor = [UIColor clearColor];
UIButton *saveButton = [[UIButton alloc]initWithFrame:CGRectMake(200, 430, 420, 30)];
[saveButton setTitle:@"Save" forState:UIControlStateNormal];
[saveButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[saveButton addTarget:self action:@selector(saveUserProfileSetting) forControlEvents:UIControlEventTouchUpInside];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(165, 200, 450, 480)];
imageView.layer.cornerRadius=10;
imageView.layer.masksToBounds = YES;
[windowBlocker addSubview:imageView];
[imageView addSubview:saveButton];
imageView.userInteractionEnabled = true;
[mainScreen addSubview:windowBlocker];
}
-(void) saveUserProfileSetting
{
// TODO: if validation is successful save the below data. and dismiss the splash screen.
NSUserDefaults *userSettings = [[NSUserDefaults alloc] init];
[userSettings setObject:fullName.text forKey:@"name_pref"];
NSLog(@"%@fullname" , fullName);
[userSettings setObject:jobTitle.text forKey:@"title_pref"];
[userSettings setObject:streetName.text forKey:@"street_name_pref"];
[userSettings setObject:suburbs.text forKey:@"suburb_pref"];
[userSettings setObject:postCode.text forKey:@"postcode_pref"];
[userSettings setObject:phoneNum.text forKey:@"phone_no_pref"];
[userSettings setObject:fax.text forKey:@"fax_pref"];
[userSettings setObject:mobileNumber.text forKey:@"mobile_no_pref"];
[userSettings setObject:email.text forKey:@"email_pref"];
[userSettings synchronize];
}
調用方法是顯示在另一個 類 - // HomeViewController。
(void)viewDidLoad
{
[super viewDidLoad];
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"isFirstLaunch"])
{
// app already launched
[[NSUserDefaults standardUserDefaults]synchronize];
}
else
{
[[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"isFirstLaunch"];
[[NSUserDefaults standardUserDefaults]synchronize];
// call this method only for the first load.
//[self performSelector:@selector() withObject:nil afterDelay:0.5];
[self performSelector:@selector(saveProfile) withObject:Nil afterDelay:0.5];
}
}
-(void) saveProfile
{
[LASplashViewer showSplashScreen];
}
日誌:
終止應用程序由於未捕獲的異常 'NSInvalidArgumentException',原因: '+ [LASplashViewer saveUserProfileSetting]:無法識別的選擇發送到類0x2a4dc'
請引導我。由於
其中具有u定義saveProfile方法? –
'[self performSelector:@selector(saveProfile)withObject:Nil afterDelay:0.5];'我覺得你的問題在這裏 – Zhans
plese看看我最近的編輯。 – LUI