View not displayed "Sometimes" Cocoa - objective-c

In my AppDelegate->applicationWillFinishLaunching i load two view controller with
NSViewController *v = [[MyCustomViewController alloc] initWithNibName:#"aNib" bundle:nil];
MyCustomViewController's initWithNibName:bundle: method is an auto-generated:
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
...
I add their view in a Custom View: [theMainView addSubview:[v view]]
I can't understand why sometimes (like one out of ten times) the views are loaded but not displayed.
EDIT:
MyCustomViewController1 *v = [[MyCustomViewController1 alloc] initWithNibName:#"aNib" bundle:nil];
[themainview addSubview:[v view]];
MyCustomViewController2 *v2 = [[MyCustomViewController2 alloc] initWithNibName:#"aNib2" bundle:nil];
[themainview addSubview:[v2 view]];
self.view1 = [[themainview subviews] objectAtIndex:0];
self.view2 = [[themainview subviews] objectAtIndex:1];
[view2 setHidden:YES];
view1 and view2 are 2 NSView properties synthesized in the AppDelegate

Your issue could be your relying on the views being at specific indexes of the themainview's subviews array. You need to be certain you're setting the correct views.
Try this instead:
MyCustomViewController1 *v = [[MyCustomViewController1 alloc] initWithNibName:#"aNib" bundle:nil];
[themainview addSubview:[v view]];
MyCustomViewController2 *v2 = [[MyCustomViewController2 alloc] initWithNibName:#"aNib2" bundle:nil];
[themainview addSubview:[v2 view]];
self.view1 = [v view];
self.view2 = [v2 view];
[view2 setHidden:YES];

Related

Shift to UIPopoverPresentationController

I want to create the same popover for my iPhone app with size GGrect of (320 100.0).
Here is my old code:
View * pk1 = [[View alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:pk1];
pop = [[UIPopoverController alloc] initWithContentViewController:nav];
[pop setDelegate:self];
[pop presentPopoverFromRect:[self btnsavepart].frame inView:[self view] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[nav release];
I using this codes but its doesn't change
nav.preferredContentSize = CGSizeMake(320, 100);
I can not change UIpopovercontriller with UIPopoverPresentationController.
How do I specify GGrect of (320 100.0)?
i thinks i can change only on horizontally but how can i do.
View *viewController = [[[View alloc] init] autorelease];
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:viewController] autorelease];
navController.modalPresentationStyle = UIModalPresentationPopover;
navController.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUp;
navController.popoverPresentationController.sourceRect = btnsavepart.bounds;
navController.popoverPresentationController.sourceView = btnsavepart;
navController.popoverPresentationController.delegate = self;
[self presentViewController:navController animated:YES completion:nil];
i want the UIPopoverPresentationController not FullScreen form in iPhone
i adding this codes but i give the FullScreen view
- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller
{
return NO;
}
I work with Xamarin but its same thing , to specify size of the popover in which you want to display your UIViewController, in the properties of your UIVIewController you have the PreferredContentSize property. There you specify the size.
I saw it somewhere here but forgot where.

UITabBarController Cropped

I have a button in a viewcontroller that loads a motherViewController. This seems to be working correctly but for some reason the newly introduced view is so tall that the content at the bottom of are cropped.
- (IBAction)LoginButton:(UIButton *)sender
{
FirstViewController *FirstView = [self.storyboard instantiateViewControllerWithIdentifier:#"First"];
SecondViewController *SecondView = [self.storyboard instantiateViewControllerWithIdentifier:#"Second"];
ThirdViewController *ThirdView = [self.storyboard instantiateViewControllerWithIdentifier:#"Third"];
FourthViewController *FourthView = [self.storyboard instantiateViewControllerWithIdentifier:#"Fourth"];
FifthViewController *FifthView = [self.storyboard instantiateViewControllerWithIdentifier:#"Fifth"];
FirstView.Username = self.UsernameBox.text;
UINavigationController *FirstNavController = [[UINavigationController alloc]init];
[FirstNavController pushViewController:FirstView animated:NO];
UINavigationController *SecondNavController = [[UINavigationController alloc]init];
[SecondNavController pushViewController:SecondView animated:NO];
UINavigationController *ThirdNavController = [[UINavigationController alloc]init];
[ThirdNavController pushViewController:ThirdView animated:NO];
UINavigationController *FourthNavController = [[UINavigationController alloc]init];
[FourthNavController pushViewController:FourthView animated:NO];
UINavigationController *FifthNavController = [[UINavigationController alloc]init];
[FifthNavController pushViewController:FifthView animated:NO];
tabBar = [[UITabBarController alloc]init];
tabBar.viewControllers = [NSArray arrayWithObjects:FirstView, SecondView, ThirdView, FourthView, FifthView, nil];
[self.view addSubview:tabBar.view];
}
I don't whether i'm right or not. But here's the answer, you are trying to add UIViewController (UITabbarController) to your ViewController. So you need to position it in your view, for example
tabbar.view.frame = CGRectMake(0, 0, 320, 460);
But only thing i don't know its how it's perfectly positioned, when we are adding to window. Try your code by setting frame for your tabbarcontroller.
try this -
tabBar.tabBar.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin;

How can I create unique PopoverView

How can I create special popOver?
I have manually created a new class, with needed design.
Then I want to load it like a PopOver
-(void) buttonAction {
UIViewController* popoverContent = [[UIViewController alloc] init];
myThirdPop * showHere;//Created class which I load as Popover
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"myThirdPop" owner:self options:nil];
showHere = [nib objectAtIndex:0];
popoverContent.view = showHere.myView;
popoverContent.contentSizeForViewInPopover = CGSizeMake(300, 350);
popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
[popoverController presentPopoverFromRect:myButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
But when I trying to tap the button, my app crashes with exc_bad_access
What`s wrong?
Use this code to create the popover
-(IBAction)Click_event
{ UIPopoverController *popoverview;
if(![popoverview isPopoverVisible])
{
Popview *pop = [[Popview alloc] initWithNibName:#"Popview" bundle:nil];
popoverview = [[UIPopoverController alloc] initWithContentViewController:pop];
[popoverview setPopoverContentSize:CGSizeMake(600.0f, 500.0f)];
[popoverview presentPopoverFromRect:CGRectMake(400, 400, 0, 0) inView:self.Click_but permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
else
{
[popoverview dismissPopoverAnimated:YES];
}
}
Lets try this. It may be helpful for you
Try this way u may fix the issue....
PopimagepickerViewController.h
UIPopoverController *popoverController;
UIPopoverController *popoverimagview; // imagepicker popoverview
PopimagepickerViewController.m
-(IBAction)popbtn_Click:(id)sender
{
UIViewController* popoverContent = [[UIViewController alloc] init];
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,230,180)];
popoverView.backgroundColor = [UIColor whiteColor];
popoverContent.view=popoverView;
popoverContent.contentSizeForViewInPopover = CGSizeMake(230, 180); // Set the popoverview Width and height
//create a popover controller
popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
CGRect popoverRect = [self.view convertRect:[popbtn frame]
fromView:[popbtn superview]];
popoverRect.size.width = MIN(popoverRect.size.width, 100) ;
popoverRect.origin.x = popoverRect.origin.x;
[popoverController
presentPopoverFromRect:popoverRect
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionUp +
UIPopoverArrowDirectionLeft //pooverview down direction
animated:YES];
[popoverView release];
[popoverContent release];
}
Your code seems overly complex, and non standard. I use this code to create a popover.
(I've edited this to match your case, but it's not tested)
-(void) buttonAction:(id) sender
{
UIViewController *myThirdPop = [[NSBundle mainBundle] loadNibNamed:#"myThirdPop" owner:self options:nil];
UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:myThirdPop];
[popoverController presentPopoverFromRect:[sender bounds] inView:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[myThirdPop release];
}

How to swap MAAttachedWindow's view

How can I swap the view of my MAAttachedWindow with the window visible?
defaultViewController = [DefaultViewController alloc] initWithNibName:#"DefaultView" bundle:nil];
attachedWindow = [[MAAttachedWindow alloc] initWithView:[defaultViewController view]
attachedToPoint:point
inWindow:nil
onSide:MAPositionBottom
atDistance:25.0];
How would I swap in AnotherViewController's view?
After a good night's sleep, it took 5-minutes to figure this out!
NSViewController *vc = [[NSViewController alloc] initWithNibName:#"MainView"
bundle:nil];
view = vc.view;
[vc release];
// Setup firstViewController here, addSubview and set current = firstViewController.view
attachedWindow = [[MAAttachedWindow alloc] initWithView:view
attachedToPoint:pt
inWindow:nil
onSide:MAPositionBottom
atDistance:5.0];
Then in my swap view method, simply:
-(void)swapView
{
SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:#"SecondView" bundle:nil];
// Resize our host view
[view setFrameSize:secondViewController.view.frame.size];
// Replace the current view
[view replaceSubview:current with:secondViewController.view];
// Resize our attachedWindow
[attachedWindow setFrame:secondViewController.view.frame display:YES];
[secondViewController release];
[current release];
}

setModalTransitionStyle and setModalPresentationStyle, set size of view

I create a UIViewController (a custom calendar and its size is 550x440) and when i push a button it must be appear; the problem is that if I use setModalPresentationStyle and setModalTransitionStyle they change size of my view; can I set the size for these presentation?
I find a solution:
[self presentModalViewController:calendar animated:YES];
calendar.view.superview.frame = CGRectMake(0, 0, 200, 200);
Maybe you want to change your design to implement your calendar as a popover:
// Define the size of the calendar view controller for the popover
UIViewController *viewController = [[UIViewController alloc] init];
viewController.contentSizeForViewInPopover = CGSizeMake(550.0f, 440.0f);
viewController.delegate = self;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
// Create the popover
UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:navigationController];
// Present the popover from one button
[popoverController presentPopoverFromBarButtonItem:button permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
//release the popover content
[viewController release];
[navigationController release];