Orientation is not working in presentViewController. Even am using category for UINavigationController. supportedInterfaceOrientations method is called but no changes. In Base viewcontroller shouldAutorotate method returns YES. Where am having the following code.
I am using this code.
ViewControllerOne *viewOne = [[ViewControllerOne alloc]init];
UINavigationController *navCtrl = [[UINavigationController alloc] initWithRootViewController:viewOne];
navCtrl.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:navCtrl animated:YES completion:nil];
Please help me. Thanks in advance...
Which simulator ios 5 or ios 6 are you using?
Post some more code.
Also see this link.
Replaced this line code in appDelegate:
[window addSubview:viewController.view];
by this line:
[window setRootViewController:viewController];
check for both iOS 5 and 6
if ([self respondsToSelector:#selector(presentViewController:animated:completion:)])
{
[self presentViewController:navigationControllerCustom animated:YES completion:nil];
}
else
{
[self presentModalViewController:navigationControllerCustom animated:YES];
}
Try using for rotation
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
Related
I execute the following code to let the user choose multiple calendars to use for my notepad app. Until iOS 10.3.1, there was no problem. On 11.0.2, it was still working on actural devices. However, since 11.1 it crashes with the following error.
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSDictionaryM setObject:forKeyedSubscript:]: key cannot be nil'
The code is as follows. Basically, I'm opening a blank calendar chooser.
if (_eventStore == nil) {
_eventStore = [[EKEventStore alloc] init];
}
// the selector is available, so we must be on iOS 6 or newer
[_eventStore requestAccessToEntityType:EKEntityTypeEvent
completion:^(BOOL granted, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (error)
{
// display error message here
}
else if (!granted)
{
// display access denied error message here
}
else
{
// access granted
EKCalendarChooser *calendarChooser = [[EKCalendarChooser alloc]
initWithSelectionStyle:EKCalendarChooserSelectionStyleMultiple
displayStyle:EKCalendarChooserDisplayAllCalendars
eventStore:_eventStore];
calendarChooser.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
calendarChooser.delegate = self;
calendarChooser.showsCancelButton = YES;
calendarChooser.showsDoneButton = YES;
NSSet *calendarSet = [[NSSet alloc] init];
calendarChooser.selectedCalendars = calendarSet;
UINavigationController *sub = [[UINavigationController alloc] initWithRootViewController:calendarChooser];
sub.navigationBar.barStyle = UIBarStyleDefault;
sub.toolbar.barStyle = UIBarStyleDefault;
[self presentViewController:sub animated:YES completion:nil];
//ios11 crashes after this
}
});
}];
Thanks for your help.
It turns out that EKCalendarChooserDisplayAllCalendars was causing the crash. Although it's not ideal, now I can avoid the crash when iOS is 11.1 or higher.
EKCalendarChooserDisplayStyle displayStyle = EKCalendarChooserDisplayAllCalendars;
if (#available(iOS 11.1, *)) {
displayStyle = EKCalendarChooserDisplayWritableCalendarsOnly;
}
EKCalendarChooser *calendarChooser = [[EKCalendarChooser alloc]
initWithSelectionStyle:EKCalendarChooserSelectionStyleMultiple
displayStyle:displayStyle
eventStore:eventStore];
I just start learning code couple months ago. I Learned from watching YouTube tutorials and Reading some online notes. Here is my situation
I have 4 storyboards. 3 of which is connected to 1 of them by segue. I have identified each of my segues with names. In my first storyboard there are 2 textfields. I want to activate each segues depending on the contents of the 2 textfields. Am i doing it correctly?
This is my ViewController.h
#interface ViewController : UIViewController <UITextFieldDelegate>
#property (strong, nonatomic) IBOutlet UITextField *text1
#property (strong, nonatomic) IBOutlet UITextField *text2
- (IBAction)buttonClick:(id)sender;
#end
And this is my ViewController.m
#synthesize text1 = _text1;
#synthesize text2 = _text2;
- (IBAction)buttonClick:(id)sender:
{
if((_text1.text = #"A")&&(_text2.text = #"B"))
{
[self performSegueWithIdentifier:#"ab" sender:self];}
else if
((_text1.text = #"B")&&(_text2.text = #"C"))
{
[self performSegueWithIdentifier:#"bc" sender:self];}
else
{self performSegueWithIdentifier:#"ca" sender:self];}
}
Am i doing it correctly?
I came up with this myself so i am not sure if it works.
Thanks!
you can trigger the segues programmatically like this(this is your own code with some corrections):
- (IBAction)buttonClick:(id)sender {
if((self.text1.text == #"A") && (self.text2.text == #"B")) {
[self performSegueWithIdentifier:#"ab" sender:self];
} else if ((self.text1.text == #"B") && (self.text2.text == #"C")) {
[self performSegueWithIdentifier:#"bc" sender:self];
} else {
[self performSegueWithIdentifier:#"ca" sender:self];
}
}
instead of using the instance variables like _text1 and _text2 you should use the properties self.text1, etc.
i have no idea why the uiactivityviewcontroller crash when i use the prensentViewController method.
it is weird, anyone has any clue?
the program is running fine not untile when i use the presenviewcontroller.
#import "ActivityViewController.h"
#interface ActivityViewController ()
#end
#implementation ActivityViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[self createTextField];
[self createButton];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void) createTextField
{
self.myTextField = [[UITextField alloc] initWithFrame:CGRectMake(20.0f, 35.0f, 280.0f, 30.0f)];
self.myTextField.translatesAutoresizingMaskIntoConstraints = NO;
self.myTextField.borderStyle = UITextBorderStyleRoundedRect;
self.myTextField.placeholder =#"Enter text to Share";
self.myTextField.delegate = self;
[self.view addSubview:self.myTextField];
}
- (void) createButton
{
self.myButtonShare = [UIButton buttonWithType:UIButtonTypeRoundedRect];
self.myButtonShare.frame = CGRectMake(20.0f, 80.0f, 280.0f, 40.0f);
self.myButtonShare.translatesAutoresizingMaskIntoConstraints = NO;
[self.myButtonShare setTitle:#"Share" forState:UIControlStateNormal];
[self.myButtonShare addTarget:self action:#selector(handleShare:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.myButtonShare];
}
- (void) handleShare:(id)sender
{
NSArray *activities = #[UIActivityTypeMail,UIActivityTypeMessage];
self.myActivityViewController = [[UIActivityViewController alloc] initWithActivityItems:#[self.myTextField.text] applicationActivities:activities];
[self presentViewController:self.myActivityViewController animated:YES completion:nil];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[self.myButtonShare resignFirstResponder];
return YES;
}
What ccjensen said is all correct, except you can actually restrict your share sheet to just Mail & Message by excluding activities, this way for example:
activityController.excludedActivityTypes = #[ UIActivityTypeCopyToPasteboard, UIActivityTypeAddToReadingList ];
This would only show the email sharing by default.
The documentation for UIActivityViewController's initWithActivityItems:applicationActivities: states that the NSArray passed as the second parameter (applicationActivities) should be an "array of UIActivity". You are passing in an array containing the two objects UIActivityTypeMail and UIActivityTypeMessage which are of type NSString *const. It seems that you were hoping that you could restrict the share sheet to only show the mail and messages activity, which is currently not possible.
To stop the crash from happening, change your code to:
<...>
self.myActivityViewController = [[UIActivityViewController alloc] initWithActivityItems:#[self.myTextField.text] applicationActivities:nil];
<...>
I have UITableview in second page then I try to navigate into third page but problem is that my code is not working. Here is the code for both AppDelegate.m file and also SecondViewController.m file,
Plz check the code and give me suggestion what i am doing wrong
SecondViewController.m file code
- (void)tableView: (UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
ThirdViewController *third = [[ThirdViewControllerr alloc] initWithNibName: #"ThirdViewControllerr" bundle:nil];
ForthViewController *forth = [[ForthViewControlle alloc] initWithNibName: #"ForthViewController" bundle:nil];
if(indexPath.row==0)
{
[[self navigationController] pushViewController:third animated:YES];
}
if(indexPath.row==1)
{
[[self navigationController] pushViewController:forth animated:YES];
}
In AppDelegate.m file i write the code for Secondviewcontroller in witch using UITableview, also i have initialized the UINavigationController inside AppDelegate.m file.If anyone have idea reply me as soon as possible,
without use UINavigationController inside AppDelegate.m file its possible for UItableview Navigation
AppsDelegate.m file
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[MobileViewController alloc] initWithNibName:#"MobileViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
self.window1=[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]bounds]];
self.viewController1=[[HealthCalculatorsViewController alloc]initWithNibName:#"HealthCalculatorsViewController" bundle:nil];
UINavigationController *nav1=[[UINavigationController alloc]initWithRootViewController:_viewController1];
self.window1.rootViewController=nav1;
[self.window1 makeKeyAndVisible];
return YES;
}
Please guide me.
Thanks.
add this in your Appdelegate.h
UINavigationController * navController;
and this in your Appdelegate.m
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
FirstViewController * viewPhone =[[FirstViewController alloc]initWithNibName:#"FirstViewController_iPhone" bundle:nil];
navController=[[UINavigationController alloc]initWithRootViewController:viewPhone];
}
else
{
FirstViewControllerController * viewPad =[[FirstViewControllerController alloc]initWithNibName:#"FirstViewController_iPad" bundle:nil];
navController=[[UINavigationController alloc]initWithRootViewController:viewPad];
}
navController.navigationBar.tintColor = [UIColor blackColor];
self.window.rootViewController=navController;
on your button click
- (IBAction)Btn_Pressed:(id)sender {
SecondViewController * second=[[SecondViewController alloc]init];
if (UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPhone)
second = [[SecondViewController alloc] initWithNibName:#"SecondViewController_iPhone" bundle:nil];
else
second = [[SecondViewController alloc] initWithNibName:#"SecondViewController_iPad" bundle:nil];
[self.navigationController pushViewController:lagrangae animated:YES];
}
if you dont want navigation bar just hide it by
[[self navigationController] setNavigationBarHidden:YES animated:YES];
I've created an app which uses the following:
SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook
SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter
The code seems to work OK and makes the posts to Facebook and Twitter but then once the posts have been completed and I return back to the app view none of the controls are active and I have to close the app and relaunch for them to work again.
I think I have nested to code incorrectly in the IF statement (posted below), so was wondering if anybody could offer any advice.
I'm very new to Xcode etc so please be patient and kind to me :-)
Thanks in advance
Pete
- (IBAction)postButton:(id)sender
{
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
SLComposeViewController *facebook = [[SLComposeViewController alloc] init];
([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]);
{
SLComposeViewController *twitter = [[SLComposeViewController alloc] init];
facebook = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[facebook setInitialText:[[self statusMessage]text]];
twitter = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[twitter setInitialText:[[self statusMessage]text]];
[self presentViewController:facebook animated:YES completion:nil];
[facebook setCompletionHandler:^(SLComposeViewControllerResult result)
{
NSString *output;
switch (result)
{
case SLComposeViewControllerResultCancelled:
output = #"Action Cancelled";
break;
case SLComposeViewControllerResultDone:
output = #"Post Sucessfull";
default:
break;
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Facebook" message:output delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
[self presentViewController:twitter animated:YES completion:nil];
[twitter setCompletionHandler:^(SLComposeViewControllerResult result)
{
NSString *output;
switch (result)
{
case SLComposeViewControllerResultCancelled:
output = #"Action Cancelled";
break;
case SLComposeViewControllerResultDone:
output = #"Tweet Sucessfull";
default:
break;
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Twitter" message:output delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
}];
}
];}
}
}