UINavigationController hides part of my view - xcode

I use storyboard, but want to load viewcontroller from xib file.
In storyboard I remove view.
Call to open viewcontroller:
- (void)SettingsButtonClick:(id)sender
{
CopyViewController* vc;
vc = [[CopyViewController alloc] initWithNibName:#"CopyViewController" bundle:nil];
[self.navigationController pushViewController:vc animated:YES];
}
But navigationcontroller hides part of my view. How can I arrange my View to start its frame below navigationcontroller?
self.view.frame = CGRectMake(0, 200, 100, 200); in viewDidLoad doesn't help me :-(

I have found solution
self.edgesForExtendedLayout = UIRectEdgeNone;

Related

Container view popover view programmatically

In iPad View I add Container View, after adding Xcode automatically create new view and connect to my main view with embed segue. Now in code I try to call this new view programmatically and cannot do this, I need to show this form with popover.
I try:
PaymentCashController *newPopup = [self.storyboard instantiateViewControllerWithIdentifier:#"PaymentCash"];
[self presentViewController:newPopup animated:YES completion:nil];
This work but show new view in full screen but I need show with popover. I try many things and all not working (.
I try this:
[self performSegueWithIdentifier:#"PaymentCash" sender:nil];
But receive exception SIGABRT
I try this:
PaymentCashController *newPopup = [self.storyboard instantiateViewControllerWithIdentifier:#"PaymentCash"];
UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:newPopup];
popoverController.popoverContentSize = CGSizeMake(500, 400);
CGRect popoverStartFrame = {50, 500, 100, 100};//Set the frame that you would like your popover to present from.
[popoverController presentPopoverFromRect: popoverStartFrame inView:self.view permittedArrowDirections: UIPopoverArrowDirectionLeft | UIPopoverArrowDirectionUp animated:YES];
Receive exception SIGABRT
Try this:
PaymentCashController *newPopup = [PaymentCashController new];
UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:newPopup];
popoverController = [[UIPopoverController alloc] initWithContentViewController:newPopup];
[popoverController presentPopoverFromRect:CGRectMake(44, 6, 111, 111) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
Same SIGABRT
You need to create UIPopoverController with your view controller and present the popover as shown below.
PaymentCashController *newPopup = [self.storyboard instantiateViewControllerWithIdentifier:#"PaymentCash"];
UIPopoverController *popoverController = [[UIPopoverController alloc] newPopup];
popover.delegate = self;
//set custom size you want for popover
popover.popoverContentSize = CGSizeMake(500, 400);
CGRect popoverStartFrame = {50, 500, 100, 100};//Set the frame that you would like your popover to present from.
[popover presentPopoverFromRect: popoverStartFrame inView:self.view permittedArrowDirections: UIPopoverArrowDirectionLeft | UIPopoverArrowDirectionUp animated:YES];
Many experiments and now all working:
Remove all segue to my popover View in Storyboard. Do it freeform and change size.
Add to my main View new property
#property (nonatomic,strong) UIPopoverController *popOver;
Set storyboard id to my popover View to "PaymentCash".
In any action on my View to show my popover View add this code:
PaymentCashController *PopoverView = [self.storyboard instantiateViewControllerWithIdentifier:#"PaymentCash"];
self.popOver =[[UIPopoverController alloc] initWithContentViewController:PopoverView];
CGRect popoverStartFrame = {1,500,200,1};
[self.popOver presentPopoverFromRect:popoverStartFrame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
Only one problem after this, popover View show in no correct place but this another question.

How to use Storyboard to make popover that can be used in code?

I'm building a collection of forms each of which contains several fields. Some of the fields are UITextFields that will display a date. I've created a new class called DatePickerTextField, a descendant of UITextField. When a DatePickerTextField is tapped I'd like for a UIDatePicker control to appear in a popover.
My question is how do I use the storyboard to implement the popover? I can do a segue when there is a specific, visible control in the scene. But how do I represent a generic popover in the scene that I can attach to any instantiated DatePickerTextField that becomes active?
You can create segue that is not connected to any control but I don't think that there would be way to specify anchor point for popover from code. Another option is to create ViewController that is not connected with any segue. When editing storyboard, create ViewController which will be placed in popover, select it and navigate to Utilities pane->Attributes Inspector. Set Size to Freeform, Status Bar to None, specify unique Identifier that will be used to instantiate ViewController from code. Now you can change the size of ViewController by selecting its View and navigating to Utilities pane->Size Inspector.
After that you can create popover from code:
- (IBAction)buttonPressed:(id)sender {
UIView *anchor = sender;
UIViewController *viewControllerForPopover =
[self.storyboard instantiateViewControllerWithIdentifier:#"yourIdentifier"];
popover = [[UIPopoverController alloc]
initWithContentViewController:viewControllerForPopover];
[popover presentPopoverFromRect:anchor.frame
inView:anchor.superview
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
One caveat is that you need to hold reference to popover as ivar of your class, otherwise it'll crash because UIPopoverController would be released and deallocated after buttonPressed returns:
#interface MyViewController : UIViewController {
// ...
UIPopoverController *popover;
// ...
}
So, I had a similar issue, and in case others might benefit, I figured I'd share it, since I benefit so much from stackoverflow.
This solution allows you to set the anchor of a customizable popover segue. It also allows you to configure the segue to be modal or not (I could not find a way to prevent the segue by dimming the exterior context, so if someone knows how to do that, I would be interested in hearing it); this is accomplished by setting the passthrough views for the popover controller. I also added the capacity to specify a custom view, rather than the view of the source viewcontroller (since I needed this capacity); this portion is not critical to the solution.
DynamicPopoverSegue.h
#interface DynamicPopoverSegue : UIStoryboardPopoverSegue
#property BOOL isModal;
#property UIView* sourceView;
#property CGRect anchor;
#end
DynamicPopoverSegue.m
#implementation DynamicPopoverSegue
- (void)perform
{
if (!self.popoverController.popoverVisible)
{
UIViewController* dst = (UIViewController*)self.destinationViewController;
UIViewController* src = (UIViewController*)self.sourceViewController;
UIView* inView = _sourceView ? _sourceView : src.view;
self.popoverController.contentViewController = dst;
if (!_isModal)
{
[self.popoverController setPassthroughViews:[[NSArray alloc] initWithObjects:inView, nil]];
}
[self.popoverController presentPopoverFromRect:_anchor
inView:inView
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
}
}
#end
Then you just set your segue to "Custom" in the storyboard, and set the segue class to "DynamicPopoverSegue". In my case, since I wanted to associate it with dynamic layers in a view, I could not set the anchor, so I created the segue by control clicking from the view controller icon in the bar beneath my view controller to the view controller I was using to present the popupover.
To call the popover segue:
[self performSegueWithIdentifier:#"MyPopoverSegue" sender:self];
And to configure the popover segue:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"MyPopoverSegue"])
{
DynamicPopoverSegue* popoverSegue = (DynamicPopoverSegue*)segue;
// set the anchor to wherever you want it to be
popoverSegue.anchor = _destinationFrame;
}
}
- (IBAction)pressItemChooseOprateRoom:(id)sender {
if (isPad){
// UIView *anchor = sender;
UIViewController *viewControllerForPopover =
[self.storyboard instantiateViewControllerWithIdentifier:#"OperateRoomList"];
_myPopover = [[UIPopoverController alloc]
initWithContentViewController:viewControllerForPopover];
CGRect rc=[self getBarItemRc:sender];
[_myPopover presentPopoverFromRect:rc
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[MLControl shared].popover =self;
// [self perfformSegueWithIdentifier:SEGUE_POP_OPERATEROOM sender:self];
}else{
[self iphoneOpenOperateRoomList];
/* [self performSegueWithIdentifier:#"iPhonePushOperateRoom" sender:self];
*/
}
}
-(void)iphoneOpenOperateRoomList{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"OperateRoomList"];
// if (!index.showTabBar) {
// vc.hidesBottomBarWhenPushed = YES;
// }
[self.navigationController pushViewController:vc animated:YES];
}
Just used the answer from Jonnywho for my SWIFT project. In case you need it:
Here's the SWIFT version:
let anchor: UIView = sender
var viewControllerForPopover = self.storyboard?.instantiateViewControllerWithIdentifier("GameAboutViewController") as! UIViewController?
let popover = UIPopoverController(contentViewController: viewControllerForPopover!)
popover.presentPopoverFromRect(anchor.frame, inView: anchor, permittedArrowDirections: UIPopoverArrowDirection.Any, animated: true)
Add a UIView in the scene dock.
You can add it as a subview to any existing view on the view controller.
You can then toggle it's isHidden property as you require.
You can add multiple such subviews and create many such popups.
This technique will save you from setting up a new View Controller and using segues.

cocoa objective c pdfview not loaded

I am a newbie for MAC development, I have a simple Cocoa Application using NSViewController where I have a main view and 2 NSViewController and dynamically flipping them. I have added PDFView on NSViewController view to show pdf pages flipping at run time. but my problem when the views are added dynamically then on PDFView I can see the pdf page after resizing the window. I tried using [[pdfViewOutlet1 view] setNeedsDisplay:YES]; for both the views.
FirstView *FirstViewController = [[FirstView alloc] initWithNibName:kFirstView bundle:nil];
[FirstViewController setPdfDoc:pdfDoc];
[FirstViewController setPageCnt:pageCnt];
self.myCurrentViewController = FirstViewController;
[[_myCurrentViewController view] setNeedsDisplay:YES];
[transition setSubtype:kCATransitionFromLeft];
[[_myTargetView animator] addSubview: [_myCurrentViewController view]];
and in the awakeFromNib: method of first view I have:
if(pdfDoc==nil )
return;
[pdfViewOutlet1 setDisplayMode: kPDFDisplaySinglePageContinuous]; //kPDFDisplaySinglePage or kPDFDisplayTwoUp;
[pdfViewOutlet1 setDocument:pdfDoc];
NSRect myRect = { { 0,0 }, { 450, 200 } };
[pdfViewOutlet1 setFrame: myRect];
[pdfViewOutlet1 goToPage: [[pdfViewOutlet1 document] pageAtIndex: pageCnt]];
[pdfDoc release];
[[pdfViewOutlet1 view] setNeedsDisplay:YES];
How can I see the pdf pages without resizing the views using mouse?
the issue is solved, i was using setWantsLayer on my Parent view which was creating the issue.

NSView subclass for NSMenuItem

I want to create a subview of NSView and link it to a MenuView.xib.
I'll have:
- MenuView.m
- MenuView.h
- MenuView.xib
in xcode I created my xib and set as customclass my 'MenuView'. Now I would like to add my new view programmatically via a command like this:
NSView *vv = [[MenuView alloc] initWithFrame:CGRectMake(0, 0, 300, 200)];
NSMenuItem *newItem = [[NSMenuItem alloc] initWithTitle:#"title" action:nil keyEquivalent:#""];
[newItem setView:vv];
but I just see an empty space without any content. How can I tell the class MenuView.m to render with the MenuView.xib file? Is that wrong?
Thanks.
Use an NSViewController, it's designed for loading views from a nib file. In your nib file, set NSViewController as the class of File's Owner and then set the view outlet of File's Owner so that it points to your view in the nib.
Then you can just do this:
NSViewController* viewController = [[NSViewController alloc] initWithNibName:#"YourNibName" bundle:nil];
YourCustomView* view = [viewController view]; //this loads the nib
[viewController release];
//do something with view
To load a view from a nib (adapted from another answer of mine):
NSNib *nib = [[NSNib alloc] initWithNibNamed:#"MenuView" bundle:nil];
NSArray *nibObjects;
if (![nib instantiateNibWithOwner:self topLevelObjects:&nibObjects]) return nil;
NSMenuItem *item = nil;
for (id obj in nibObjects)
if ([obj isKindOfClass:[NSMenuItem class]]) {
item = obj;
break;
}
[someView insertSubview:item];
If you want something other than self as the file owner, change the parameter to instantiateNibWithOwner:.

Xcode - UILabel is not changing value on viewDidAppear

Hey everyone, I have a iPhone App I am creating. It uses a uitableview and that goes to a detail view.
Now on the detail view I have a scroll view, and all the data (XML) comes into it fine, each time, no issues.
My UILabels in my scrollview do update with the correct data, but, they keep adding subviews on top of each other to keep adding label after label and it all looks mumbo jumbo.
I have tried everything to try and remove the subviews such as:
for(UIView *subview in [scrollView subviews]) {
[subview removeFromSuperview];
}
AND
[[scrollView subviews] makeObjectsPerformSelector:#selector(removeFromSuperview)];
So I am stumped, I got no idea what is happening. Any help? I have been searching Google for ages and agesm, but keep finding the same answers that don't work :(
Any direction to sites that might help that you know of will be greatly appreciated.
Thanks!
Here is what I have in my controller that loads all the scrollview and labels:
- (void)viewDidAppear:(BOOL)animated {
// Create the scroll view for this view
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
scrollView.contentSize = CGSizeMake(320, 270);
[scrollView setFrame:CGRectMake(0, 198, 320, 170)];
// Do the labels for the text
UILabel *dates = [[UILabel alloc] initWithFrame:scrollView.bounds];
dates.textColor = [UIColor whiteColor];
dates.font = [UIFont boldSystemFontOfSize:12];
dates.text = round_date;
dates.tag = 1;
[dates setBackgroundColor:[UIColor clearColor]];
[dates setFrame:CGRectMake(10, 10, 280, 22)];
[scrollView addSubview:dates];
[dates release];
// Add the content to the main scrollview
[self.view addSubview:scrollView];
[scrollView release];
}
Ok, the reason for this is that viewDidAppear will get called every time you present the view.
If you do this is
-(void) viewDidLoad;
instead.
To make sure you can access them later you might want to keep a reference to them in your UIViewController
-(void) viewDidLoad {
scrollView = [[UIScrollView alloc] initWithFrame];
[self.view addSubview:scrollView];
}
and define it in your header file with:
UIScrollView *scrollView;

Resources