我需要帮助,谷歌搜索也让我毫不知情,因此我会在这里发布指导和协助。
我的情况是,当你按下确定后我想要app delegate.m,我想要一个简单的重定向回到另一个视图。这可能吗?
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateActive) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Daily Vibes"
message:notification.alertBody
delegate:self cancelButtonTitle:@"Okay"
otherButtonTitles:nil];
[alert show];
}
有可能做到吗?点击取消按钮后,他们将只是重定向到特定页面的应用程序???
答案 0 :(得分:1)
试试这个:
让你的app delegate符合UIAlertViewDelegate协议,并添加以下代码:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:@"Okay"])
{
NSLog(@"Okay was selected.");
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
MyViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"MyViewController"];
[(UINavigationController*)self.window.rootViewController pushViewController:vc animated:NO];
}
else if([title isEqualToString:@"Hello"])
{
NSLog(@"Hello was selected.");
}
}
代表捕获所选按钮,检查标题,并采取相应措施。在这种情况下,由于您在应用程序委托中,您必须手动按下视图控制器(您不在视图控制器中,因此不允许推送)