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];
Related
I'm trying next way:
Message *message = self.messagesArray[indexPath.row];
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:LocalizedString(#"FirstAction")
message:#""
preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *editMessage = [UIAlertAction actionWithTitle:LocalizedString(#"SecondAction") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
}];
[alertController addAction:editMessage];
UIAlertAction *forwardMessage = [UIAlertAction actionWithTitle:LocalizedString(#"ThirdAction") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
}];
[alertController addAction:forwardMessage];
UIAlertAction *deleteMessage = [UIAlertAction actionWithTitle:LocalizedString(#"DeleteMessage") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
}];
[alertController addAction:deleteMessage];
[self setSourceViewForAlertController:alertController];
[self presentViewController:alertController animated:YES completion:nil];
[self createMenuForMessage:message];
[[UIMenuController sharedMenuController] setMenuVisible:YES animated:YES];
So, my aim is to present alertcontroller for UICollectionViewCell and UIMenuController at the same time.
Like this:
Your issue is related to where are you showing your UIMenuController you have to take in account that UIView must have implemented the canBecomeFirstResponder method returning YES
- (IBAction)action:(id)sender {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:#""
message:#""
preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *editMessage = [UIAlertAction actionWithTitle:#"Edit" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
}];
[alertController addAction:editMessage];
UIAlertAction *forwardMessage = [UIAlertAction actionWithTitle:#"Move" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
}];
[alertController addAction:forwardMessage];
UIAlertAction *deleteMessage = [UIAlertAction actionWithTitle:#"Delete" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
}];
[alertController addAction:deleteMessage];
[self presentViewController:alertController animated:YES completion:nil];
[[UIMenuController sharedMenuController] setTargetRect:self.view.bounds inView:self.view];
[[UIMenuController sharedMenuController] setArrowDirection:UIMenuControllerArrowDefault];
[[UIMenuController sharedMenuController] setMenuItems:#[[[UIMenuItem alloc]initWithTitle:#"test" action:#selector(didReceiveMemoryWarning)]]];
[[UIMenuController sharedMenuController] setMenuVisible:YES animated:YES];
}
-(BOOL)canBecomeFirstResponder{
return true;
}
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];
In my app i am getting unknown error,while moving from one controller to another by using this code,
-(IBAction)backQA:(id)sender
{
UIAlertController *alert =[UIAlertController alertControllerWithTitle:#"Attention" message:#"Are You Sure Quit The Exam!" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *ok = [UIAlertAction actionWithTitle:#"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
ContestViewController *contestVC =[self.storyboard instantiateViewControllerWithIdentifier:#"ContestVC"];
[self presentViewController:contestVC animated:YES completion:nil];
}];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:#"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
}];
[alert addAction:ok];
[alert addAction:cancel];
[self presentViewController:alert animated:YES completion:nil];
}
When i click on my Ok action i am getting error.
Here is the screen shot,
Any help?
Here is the my setMainBanner Method.
- (void)viewDidLoad
{
#try
{
if((NSNull *)[contestDict objectForKey:#"mainbanner"] != [NSNull null])
{
if([[contestDict objectForKey:#"mainbanner"] length] > 0)
{
NSString *mainBannerimage = [contestDict objectForKey:#"mainbanner"];
NSString *bannerImageURL = [NSString stringWithFormat:#"http://www.karo.com/APP/banners/%#", mainBannerimage];
NSURL *imageURL = [NSURL URLWithString:bannerImageURL];
[mainBanner sd_setImageWithURL:imageURL
placeholderImage:[UIImage imageNamed:#"profilepic_bg"]];
}
else
{
}
}
}
#catch (NSException *exception)
{
}
}
Try this:
UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:alertTitle
message:alertMessage
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction
actionWithTitle:NSLocalizedString(#"Cancel", #"Cancel action")
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *action)
{
NSLog(#"Cancel action");
}];
UIAlertAction *okAction = [UIAlertAction
actionWithTitle:NSLocalizedString(#"OK", #"OK action")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action)
{
NSLog(#"OK action");
}];
[alertController addAction:cancelAction];
[alertController addAction:okAction];
Finally we can present the alert view controller as with any other view controller:
[self presentViewController:alertController animated:YES completion:nil];
why you are using presentViewController use this
[self dismissViewControllerAnimated:YES completion:nil];
i Create two buttons of UIAlertcontroller:
One Button - "OpenCamera"
Two button - "OpenGallery"
I just can not understand how I create action when I click on one of them.
- (IBAction)takePic:(id)sender {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil
message:nil
preferredStyle:UIAlertControllerStyleActionSheet]; // 1
UIAlertAction *openCamrea = [UIAlertAction actionWithTitle:#"open camrea"
style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
}];
UIAlertAction *openGallery = [UIAlertAction actionWithTitle:#"open gallery"
style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
}];
[alert addAction:openCamrea];
[alert addAction:openGallery];
[self presentViewController:alert animated:YES completion:nil];
}
The handler is the block to be executed on the selection of the item.
UIAlertAction *openGallery = [UIAlertAction
actionWithTitle:#"open gallery"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
// Code to run when the open gallery option is pressed.
}];
BTW I think the long unbroken lines in the question really don't help as they effectively hide the key parameter.
The complete code:
- (IBAction)takePic:(id)sender {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil
message:nil
preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *openCamrea = [UIAlertAction actionWithTitle:#"open camrea"
style:UIAlertActionStyleDefault handler:^(UIAlertAction * action)
{
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:#"Error"message:#"Device has no camera"delegate:nil cancelButtonTitle:#"OK"otherButtonTitles: nil];
[myAlertView show];
}
else
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
}];
UIAlertAction *openGallery = [UIAlertAction actionWithTitle:#"open gallery"
style:UIAlertActionStyleDefault handler:^(UIAlertAction * action)
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}];
[alert addAction:openCamrea];
[alert addAction:openGallery];
[self presentViewController:alert animated:YES completion:nil];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.img.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:NULL];
}
Put your code inside the handler blocks you are passing to [UIAlertAction actionWithTitle:style:handler:]
For example:
UIAlertAction *openCamrea = [UIAlertAction actionWithTitle:#"open camrea"
style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
// openCamera action code goes here
}];
UIAlertAction *openGallery = [UIAlertAction actionWithTitle:#"open gallery"
style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
// openGallery action code goes here
}];
I've a UIAlertController and I've a bunch of UIAlertAcion Buttons. Now I need to show one button with other Color rather than the same color.
For Ex
Button1
Button2
Button3
Button1 and button3 should be in blue
and
button2 should be in red.
Is it possible ? How?
Just Throw your thoughts
...
My Code:
UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:#"Food Menu" message:#"Select the MenuItem" preferredStyle:UIAlertControllerStyleActionSheet];
for(int i= 0; i<[menus count];i++){
UIAlertAction *action = [UIAlertAction actionWithTitle:[menu objectAtIndex:i] style:UIAlertActionStyleDefault handler:^(UIAlertAction* action){
[actionSheet dismissViewControllerAnimated:YES completion:nil];
//do SomeWork
}];
if(i==currentIndex){
//Put button Color Red
}
else{
//put button color Blue
}
[actionSheet addAction:action];
}
UIAlertAction *cancel = [UIAlertAction actionWithTitle:#"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction* action){
[actionSheet dismissViewControllerAnimated:YES completion:nil];
}];
[actionSheet addAction:cancel];
[self presentViewController:actionSheet animated:YES completion:nil];
}
do like change the alert style:UIAlertActionStyleDestructive
UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:alertTitle
message:alertMessage
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction
actionWithTitle:NSLocalizedString(#"Cancel", #"Cancel action")
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *action)
{
NSLog(#"Cancel action");
}];
UIAlertAction *resetAction = [UIAlertAction
actionWithTitle:NSLocalizedString(#"Reset", #"Reset action")
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction *action)
{
NSLog(#"Reset action");
}];
UIAlertAction *okAction = [UIAlertAction
actionWithTitle:NSLocalizedString(#"OK", #"OK action")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action)
{
NSLog(#"OK action");
}];
[alertController addAction:cancelAction];
[alertController addAction:resetAction];
[alertController addAction:okAction];
[self presentViewController:alertController animated:YES completion:nil];