else {
[[[UIAlertView alloc] initWithTitle:NSLocalizedString(#"Error", nil)
message:NSLocalizedString(#"Camera not available.", nil)
delegate:nil
cancelButtonTitle:NSLocalizedString(#"OK", nil)
otherButtonTitles:nil] show];
self.result(nil);
self.result = nil;
_arguments = nil;
}
}
I am getting this error and I tried to change 'UIAlertView' to 'UIAlertController'still getting different errors.
You can replace in xCode build with below UIAlertController:
UIAlertController *alert = [UIAlertController
alertControllerWithTitle:#"Error" message:#"Camera not available"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *ok = [UIAlertAction actionWithTitle:#"Ok" style: style:UIAlertActionStyleDefault handler:nil];
[alert addAction:ok];
[self presentViewController:alert animated:YES completion:nil];
Related
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIAlertController *alert = [[UIAlertView alloc] initWithTitle:#"Alert"
message:#"Are you sure you want to Delete your account ?"
delegate:self
cancelButtonTitle:#"Delete Account"
otherButtonTitles:#"Cancel", nil];
UIAlertAction* ok = [UIAlertAction actionWithTitle:#"OK" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
//Do Some action here
[[NSUserDefaults standardUserDefaults] removeObjectForKey:#"logged_in"];
// alert.tag = 104;
// [alert show];
[self displayAlertForRemoveAccountWithMessage:#"Are you sure you want to Delete your account ?"];
UINavigationController *nav = [self.storyboard instantiateViewControllerWithIdentifier:#"stratingNav"];
[nav setModalPresentationStyle: UIModalPresentationOverFullScreen];
[self presentViewController:nav animated:YES completion:nil];
}];
UIAlertAction* cancel = [UIAlertAction actionWithTitle:#"Cancel" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
[alert dismissViewControllerAnimated:YES completion:nil];
}];
[alert addAction:ok];
[alert addAction:cancel];
[self presentViewController:alert animated:YES completion:nil];
}
- (void)displayAlertForRemoveAccountWithMessage :(NSString *)message
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Alert"
message:message
delegate:self
cancelButtonTitle:#"Delete Account"
otherButtonTitles:#"Cancel", nil];
alert.tag = 103;
[alert show];
}
i am trying to implement delete account function with objective c kindly please tell me what else need to be added in this code..
How to change this obj c code that suits with iOS 9 above ? i have this error when i updating X Code into 8.2.1 . The code as below
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:#"Continue"]){
NSLog(#"Continue...");
[self performSegueWithIdentifier:#"createlogin" sender:self];
}
}
The error:
UIAlertView is deprecated : first deprecated in iOS 9.0 - UIAlertView
is deprecated. Use UIAlertController with a preferredStyle of
UIAlertControllerStyleAlert instead
Thanks.
UIAlertController * alert = [UIAlertController alertControllerWithTitle:#"Add Title" message:#"Add Message" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction * actionOK = [UIAlertAction actionWithTitle:#"Button Title" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//Here Add Your Action
}];
UIAlertAction * actionCANCEL = [UIAlertAction actionWithTitle:#"Second Button Title" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//Add Another Action
}];
[alert addAction:actionOK];
[alert addAction:actionCANCEL];
[self presentViewController:alert animated:YES completion:nil];
Use this Method if any need ask me and for more Information use this Link http://useyourloaf.com/blog/uialertcontroller-changes-in-ios-8/
Use this code
UIAlertController *alert = [UIAlertController alertControllerWithTitle:#"Title" message:#"Message" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction * continueButton = [UIAlertAction actionWithTitle:#"Continue" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action){
[self performSegueWithIdentifier:#"createlogin" sender:self];
}];
UIAlertAction * cancelButton = [UIAlertAction actionWithTitle:#"cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action){
}];
[alert addAction:continueButton];
[alert addAction:cancelButton];
[self presentViewController:alert animated:YES completion:nil];
try this:
UIAlertController *controller = [UIAlertController alertControllerWithTitle:#"Your message title"
message:#"Enter your message here."
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:#"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action)
{
NSLog(#"Ok Action");
}];
UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:#"Skip" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action)
{
NSLog(#"Cancel Action");
}];
[controller addAction:okAction];
[controller addAction:cancelAction];
[self presentViewController:alertController animated:YES completion:nil];
When I use UIAlertController with addTextField on iPad, the keyboard doesn't rotate properly from iOS10.
It was working fine with iOS9, does anybody know the way to fix it?
UIAlertController *alert = [UIAlertController
alertControllerWithTitle:#"title"
message:nil
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *done = [UIAlertAction actionWithTitle:NSLocalizedString(#"Done", nil)
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
UITextField *textField = alert.textFields.firstObject;
}];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:NSLocalizedString(#"Cancel", nil)
style:UIAlertActionStyleCancel
handler:nil];
[alert addAction:cancel];
[alert addAction:done];
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
}];
[self presentViewController:alert animated:YES completion:nil];
self.infoView.hidden = NO;
self.infoView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.7];
i want to call thin in table view
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row==0) {
return;
}
NSMutableDictionary *Tag_Dic = [NSMutableDictionary dictionary];
[Tag_Dic setObject:[NSNumber numberWithInteger:indexPath.row] forKey:#"Tags"];
[[NSNotificationCenter defaultCenter] postNotificationName:#"MoveToNext" object:self userInfo:Tag_Dic];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setInteger:indexPath.row forKey:#"SenderTag"];
[defaults synchronize];
}
Try this. You have to show alertController when tapped on UITableViewCell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
[cell.button addTarget:self action:#selector(presentAlert) forControlEvents:UIControlEventTouchUpInside];
}
Then write your code for UIAlertController in presentAlert selector.
UIAlertController * alert= [UIAlertController
alertControllerWithTitle:#"Title"
message:#"message"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* ok = [UIAlertAction
actionWithTitle:#"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
}];
UIAlertAction* cancel = [UIAlertAction
actionWithTitle:#"Cancel"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
[alert dismissViewControllerAnimated:YES completion:nil];
}];
[alert addAction:ok];
[alert addAction:cancel];
[self presentViewController:alert animated:YES completion:nil];
If you want to show alert when tableview cell is clicked then do following in didSelectRowAtIndexPath method.
For iOS 9 and earlier,
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Title" message:#"Message" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Button1",#"Button2", nil];
alertView.delegate = self;
[alertView show];
and user UIAlertView's delegate method to implement your logic when button is clicked
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
For iOS 9 and onwards (UIAlertView is deprecated.)
UIAlertAction *actionOK = [UIAlertAction actionWithTitle:#"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//handel when OK button is pressed.
}];
UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:#"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
//handel when Cancel button is pressed.
}];
UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:#"Title" message:#"Message" preferredStyle:UIAlertControllerStyleAlert];
[alertVC addAction:actionOK];
[alertVC addAction:actionCancel];
[self presentViewController:alertVC animated:true completion:nil];
In ios 8.3 and earlier work this code,
- (void)saveButton {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Title" message:#"Message" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
After 8.4 popup action used UIAlertController and i have create the UITextField in popup view and action is give below,
- (void)callAlert {
UIAlertController *alert= [UIAlertController
alertControllerWithTitle:#"Enter Folder Name"
message:#"Keep it short and sweet"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* ok = [UIAlertAction actionWithTitle:#"OK" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action){
//Do Some action here
UITextField *textField = alert.textFields[0];
NSLog(#"text was %#", textField.text);
}];
UIAlertAction* cancel = [UIAlertAction actionWithTitle:#"Cancel" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
NSLog(#"cancel btn");
[alert dismissViewControllerAnimated:YES completion:nil];
}];
[alert addAction:ok];
[alert addAction:cancel];
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = #"folder name";
textField.keyboardType = UIKeyboardTypeDefault;
}];
[self presentViewController:alert animated:YES completion:nil];
}
Finally call this method where you want, hope its helpful.
I have updated for XCode 6.0.1, iOS 8.0 and after that used UIAlertController instead of UIAlertView but Title for the UIAlertController is not appearing.
For Reference see code:
UIAlertController *alert = [UIAlertController alertControllerWithTitle:#"AlertView" message:#"Please Click" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:#"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action)
{
}];
UIAlertAction* cancel = [UIAlertAction actionWithTitle:#"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action)
{
[alert dismissViewControllerAnimated:YES completion:nil];
}];
[alert addAction:defaultAction];
[alert addAction:cancel];
[self presentViewController:alert animated:YES completion:nil];
What you are presenting is actually an action sheet, which is not equivalent to the UIAlertView. You should change preferredStyle, use UIAlertControllerStyleAlert instead UIAlertControllerStyleActionSheet:
UIAlertController *alert = [UIAlertController alertControllerWithTitle:#"AlertView" message:#"Please Click" preferredStyle:UIAlertControllerStyleAlert];
[self presentViewController:alert animated:YES completion:nil];
Now, where are the buttons? You can add for example (before presentViewController):
[alert addAction:[UIAlertAction actionWithTitle:#"Ok" style:UIAlertActionStyleDefault handler:nil]];
And then create your action to implement the handler.