[英]How to navigate to a view controller on a new storyboard file in objective-c
[英]How to show a new view controller if the alert is validated? (objective c)
如果要验证警报,我想更改视图控制器,而不是按钮,但我不知道该怎么做。 我使用可可豆荚进行通知(只是因为设计很漂亮)。 欢迎每个答案!
- (IBAction)changeTheme:(UIButton *)sender {
// for changing view controller
[UIView animateKeyframesWithDuration:1.0 delay:0 options:0 animations:^{
changeTheme.transform = CGAffineTransformMakeScale(2, 2);
} completion:^(BOOL finished) {
// init alert with options
SCLAlertView *changeThemeNotification = [[SCLAlertView alloc] init];
// to sport
[changeThemeNotification addButton:@"change to sport" validationBlock:^BOOL{
BOOL passedValidation = true;
return passedValidation;
} actionBlock:^{
}];
// to food
[changeThemeNotification addButton:@"change to food" validationBlock:^BOOL{
BOOL passedValidation = true;
return passedValidation;
} actionBlock:^{
[self.view setBackgroundColor:[UIColor blackColor]];
}];
// to animal
[changeThemeNotification addButton:@"change to animal" validationBlock:^BOOL{
BOOL passedValidation = true;
return passedValidation;
} actionBlock:^{
[self.view setBackgroundColor:[UIColor greenColor]];
}];
// else (message & options)
[changeThemeNotification showCustom:self image:nil color:[self.colorWheel randomColor] title:@"Test" subTitle:@"This is a test notification for the navigation." closeButtonTitle:@"stay" duration:0.0f];
changeThemeNotification.hideAnimationType = SlideOutToBottom;
changeThemeNotification.shouldDismissOnTapOutside = YES;
changeThemeNotification.soundURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/url_to_sound.mp3", [[NSBundle mainBundle] resourcePath]]];
}];
}
以下代码将有所帮助:
要检查iOS版本:
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
要显示警报视图:
if(SYSTEM_VERSION_LESS_THAN(@"8.0"))
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@""
message:@"your message"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"OK", nil];
[alert show];
}
else
{
UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:@""
message:@"You message..."
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction
actionWithTitle:NSLocalizedString(@"OK", @"OK action")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action)
{
[self performSegueWithIdentifier:@"yourSegueName" sender:self];
}];
[alertController addAction:okAction];
[self presentViewController:alertController animated:YES completion:nil];
}
对于iOS <8.0,还可以使用以下代码来处理“确定”按钮。
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0)
{
[self performSegueWithIdentifier:@"yourSegueName" sender:self];
}
else
{
}
}
尝试这个
SCLAlertView *changeThemeNotification = [[SCLAlertView alloc] init];
[changeThemeNotification addButton:@"change to sport" validationBlock:^BOOL{
BOOL passedValidation = true;
return passedValidation;
} actionBlock:^{
[self performSegueWithIdentifier:@"yourSegueName" sender:self];
}];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.