UIAlertView代理方法崩溃 [英] UIAlertView delegate method crashing
问题描述
在我的iPhone应用程序中,我有一个 NSObject
一个类和一个 UIViewController
B类。我想从A调用B类中的一个实例方法。我使用以下代码。
In my iPhone app, I have a NSObject
A class and a UIViewController
B class. I want to call a instance method in B class from A. I used the following code.
Bclass *vc = [[Bclass alloc]init];
[vc hideAlert:NSString];
[vc release];
和B类:
- (void)hideAlert:(NSString*)message{
UIAlertView *shareAlrt = [[UIAlertView alloc] initWithTitle:@""
message:message
delegate:self
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[shareAlrt show];
[shareAlrt release];
}
并调用该方法并显示一个AlertView。点击确定按钮,我想导航到Cc类。
and the method called and show a AlertView. When click on the Ok button, I want to navigate to class Cclass.
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
Cclass *vc = [[Cclass alloc]initWithNibName:@"Cclass" bundle:[NSBundle mainBundle]];
[self presentModalViewController:vc animated:NO];
[vc release];
}
}
但是当我点击Ok按钮,应用程序崩溃这里发生了什么?我已经在B class.h文件中添加了< UIAlertViewDelegate>
,但仍然是相同的错误。请帮助
But when I click on the Ok button, the app crashes. Whats happening here? I have added <UIAlertViewDelegate>
in the B class.h file, but still the same error. Please help
我收到错误代码 ***由于未捕获异常'NSInvalidArgumentException'终止应用程序,原因:' - [__ NSCFType alertView: clickedButtonAtIndex:]:无法识别的选择器发送到实例0x81baa80'
推荐答案
只需更改方法
- (void)hideAlert:(NSString*)message{
UIAlertView *shareAlrt = [[UIAlertView alloc] initWithTitle:@""
message:message
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"Ok",nil];
[shareAlrt show];
[shareAlrt release];
}
这篇关于UIAlertView代理方法崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!