[英]How to show UIAlertView of one view controller class from AppDelegate and to hit clicked button at index method if alert button clicked?
我正在調用一個顯示UIAlertview的視圖控制器方法,並且正在顯示alertview,但是未調用索引方法上的單擊按鈕。 如何解決?
以下代碼已在TestViewController類中使用
- (void) test
{
UIAlertView *alert1 = [[UIAlertView alloc]initWithTitle:@"OPTUM" message:NSSAlertMessage delegate:self cancelButtonTitle:@"NO" otherButtonTitles:@"YES", nil];
alert1.tag = 3;
[alert1 show];
}
然后從應用程序委托調用上述方法,
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSLog(@"Notification Received: %@", userInfo);
NSString *NSSMessage = [NSString stringWithFormat:@"%@", userInfo];
UIStoryboard *storyboard=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
TestViewController *obj1=[storyboard instantiateViewControllerWithIdentifier:@"View Controller"];
[obj1 handleNotificationMessage: NSSMessage];
}
在此先感謝您的幫助。
確保您的調用視圖控制器被聲明為UIAlertViewDelegate:
@interface TestViewController : UIViewController<UIAlertViewDelegate>
並確保clickedButtonAtIndex
具有正確的簽名:
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.