2014-03-05 23 views
1

我有一个UIAlertView中,alertView,即在viewDidLoad中-方法初始化,如:使用在不同的地方相同的UIAlertView中

self.alertView = [[UIAlertView alloc] initWithTitle:@"Meddelande" 
              message:@"Do you want to continue?" 
              delegate:self 
            cancelButtonTitle:@"No" 
            otherButtonTitles:@"Yes", nil]; 

我也有一些metods的由pressning不同的按钮叫:

- (IBAction)didPressButton1 { 

    [self.alertView show]; 
} 

我因子评分,这将显示alertView,但没有任何反应。一种解决方法是调用初始化的alertView并显示在同一时间梅托德,但我想这个工作。

的alertView的性质是这样的:

@property (nonatomic, strong) UIAlertView *alertView; 

我还添加了在类扩展这样的delegats:

@interface MyViewController() <UIAlertViewDelegate> 
@end 

我在做什么错?

汉克

+1

你能告诉我你定义的alertView属性吗? –

+0

您是否添加了UIAlertViewDelegate? –

回答

1

你没有什么不好。此代码有效。你错就错在你如何申报您的alertView

要确保你做,所以

@property (nonatomic, retain)UIAlertView *alertView; 

,你是你的didPressButton1方法连接到您的UIButton

+0

感谢的,男人!现在它工作了! – iHank

1

在接口(.h)文件中

@interface Your_Class:NSObject <UIAlertViewDelegate> 

@property (strong, nonatomic) UIALertView *uv; 

//在实施文件

@synthesize uv; 

//在viewDidLoad中

self.uv = [[UIAlertView alloc] initWithTitle:@"Meddelande" 
              message:@"Do you want to continue?" 
              delegate:self 
            cancelButtonTitle:@"No" 
            otherButtonTitles:@"Yes", nil]; 

//在按钮操作

- (IBAction)didPressButton1 { 

    [self.uv show]; 
} 
0

你检查你的didPressButton1方法调用或不? 如果不是,那么请以适当的方式将其连接。

相关问题