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];
Related
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];
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 problem, my app using default uiactivityviewcontroller, but it too big on iphone 6+. How to fix it ?
Button in my app too big
Button other app
My code
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
mail.mailComposeDelegate = self;
[self presentViewController:mail animated:YES completion:NULL];
UIAlertController *actionSheet= [UIAlertController
alertControllerWithTitle:nil
message:nil
preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *actionSheetDeleteDraft = [UIAlertAction
actionWithTitle:#"Delete Draft"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
NSLog(#"Delete is pressed");
}];
UIAlertAction *actionSheetSaveDraft = [UIAlertAction
actionWithTitle:#"Save Draft"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
NSLog(#"Save pressed");
}];
UIAlertAction *actionSheetCancel = [UIAlertAction
actionWithTitle:#"Cancel"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction * action)
{
NSLog(#"Cancel pressed");
}];
[actionSheet addAction:actionSheetDeleteDraft];
[actionSheet addAction:actionSheetSaveDraft];
[actionSheet addAction:actionSheetCancel];
[self presentViewController:actionSheet animated:YES completion:nil];
So, I'm stumped...Here's the image for quick reference: http://i.imgur.com/zM1VJdi.png
The issue is that when a textField is added to a UIAlertController, the textfield's height is larger than one line, and goes underneath the UIAlertController buttons. Any thoughts on why this could be happening?
Here's the code:
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:#"Title"
message:#"Message"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:#"Cancel"
style:UIAlertActionStyleCancel
handler:nil];
UIAlertAction *resetDataAction = [UIAlertAction actionWithTitle:#"Delete"
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction *action) {
// handler code
}];
[alertController addAction:resetDataAction];
[alertController addAction:cancelAction];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
//handler code
}];
[self presentViewController:alertController animated:YES completion:nil];
because you add buttons then your text field.
[alertController addAction:resetDataAction];
[alertController addAction:cancelAction];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
//handler code
}];
but you need to do it like that
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
//handler code
}];
[alertController addAction:resetDataAction];
[alertController addAction:cancelAction];
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.