I am using an NSViewController to load a nib with a view that renders a Core-Plot chart. I replace the "target view" using the following code:
NSViewController* aViewController = [[NSViewController alloc] initWithNibName:#"nib name" bundle:nil];
if (aViewController != nil)
{
myCurrentViewController = aViewController;
}
// embed the current view to our host view
[myTargetView addSubview: [myCurrentViewController view]];
[[myCurrentViewController view] setFrame: [myTargetView bounds]];
This results in basically everything in the chart looking slightly fuzzy. I commented out the setFrame and also tried integer values for the setFrame and it made no difference. The target view also does not have layering on.
If I get rid of the view controller and change myTargetView to the actual chart view class(PlotView) then it is no longer fuzzy. This is on 10.8. Any idea why using the NSViewController route is messing up the chart view?
Update #1: I am using from the Plot_Gallery_Mac sample project the PlotGalleryController, PlotView, PlotItem, and VerticalBarChart to generate the chart through an NSViewController. I am guessing the setup in the sample PlotItem class (particularly the renderInView method) is not compatible with using it with an NSViewController.
Related
I want to add a image in the navbar as title. I'm using the following code in AppDelegate.m file
self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"akskeving_logo.png"]];
I'm gettin the following error: Property 'navigationItem'not found on object of type 'HsAppDelegate'
You are trying to access the navigationItem property of your app delegate, but it doesn’t have that property. navigationItem is a property of UIViewController. Something along these lines (details may be different for your app):
self.rootViewController.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"akskeving_logo.png"]];
Edit: actually, that is probably not exactly what you want to do. You should be accessing the navigationItem of the view controller that you are presenting in the navigation controller. So,
self.somePresentedViewController.navigationItem.titleView = …;
In trying to attempt to use Apple's UIViewController containment I have encountered a problem with animating the transition between two UIViewControllers.
Here is the set up... I have created a UITabBarController and within one of the tabs I have created a UIViewController as a container. This ViewController manages the transition between a UIViewController and a UINavigationController. The before view is:
When the Next button is tapped the view begins it's transition with a flipFromRight transition. During the transition, the Navigation bar is in "to" view but is located 20pixels down from the top edge of the view. Picture below:
The green is the background color of the container view. Once the new view completes the transition, the Navigation bar snaps up to the top of the view and the final result is:
The time to snap in place is independent of the duration of the animation. I achieve the final state that I want, but the transition is a problem.
I have instrumented the viewController lifecycle and the frames of the Navigation bar and the UITableView are as specified in the XIB. The xib looks like this:
Here is the code:
In -viewDidLoad -
_fromVC = [[FromVC alloc] initWithNibName:#"FromVC" bundle:nil delegate:self];
[self addChildViewController:_fromVC];
[self.view addSubview:_fromVC.view];
[_fromVC didMoveToParentViewController:self];
In my button handler -
- (void)buttonSelected
{
//
// Create the "to" View controller
//
ToVC *toVC = [[ToVC alloc] initWithNibName:#"ToVC" bundle:nil];
//
// Create the navigation controller for the study activity
//
_toNavCon = [[UINavigationController alloc] initWithRootViewController:toVC];
[self addChildViewController:_toNavCon];
[_fromVC willMoveToParentViewController:nil];
[self transitionFromViewController:_fromVC
toViewController:_toNavCon
duration:0.7
options:UIViewAnimationOptionTransitionFlipFromRight
animations:nil
completion:^(BOOL finished) {
[_fromVC removeFromParentViewController];
[_toNavCon didMoveToParentViewController:self];
}];
}
There is no code in "to" view controller that changes the appearance of the view controller.
Another bit of information... When I "toggle In-Call status bar" in the simulator the gap at the top of the navigation bar is the height of the In-Call status bar.
I have looked at everything on the web and there is nothing that helps. Has anyone seen this and has anyone fixed it?
I did find an answer!! Subclass UINavigationController and override
- (BOOL)wantsFullScreenLayout{
return NO;
}
Apparently, UINavigationController and UITabController always want the full screen (default YES) - adjusting for the status bar - and you can not set this property any other way. It has been working for me.
So basically I have this project, where I have 4 different tab bar pages. 2 of them uses navigation controller & tab bar, and 2 are just view controllers. Now there is this one viewcontroller, which I need to add a scroll view to. So basically, I click on the item in the tab bar, it takes me to a view controller, where I can scroll down and up. I have been following Youtube Video Link, but I do not get it to work. The problem is that I use the exact code, and I change the ViewController class to the .h and .m name (ScrollViewViewController), and I put in a scroll view that has 320 x 1000, and a button at the top, but it doesn't scroll! How can I solve this problem?
Note: That if you don't know my problem, but could very detailed walk me through on how to add a scroll view to storyboards in xcode 4.2, then that would be amazing :)!
scrollerViewController.m:
- (void)viewDidLoad {
[scroller setScrollEnabled:YES];
[scroller setContentSize:CGSizeMake(320, 1000)];
[super viewDidLoad];
}
scrollerViewController.h
#interface scrollerViewController : UIViewController {
IBOutlet UIScrollView *scroller;
}
#end
And here comes a picture of the storyboard.
I need some of the code in order to really know your problem, but let me throw in my guess. You may be setting the size 320x1000 to the frame size of the scrollview by any chance? The frame size of the scrollview has to stay 320x480, and the contentSize should be 320x1000. Sorry if it was a wrong guess, but shouldn't do any harm :)
Something like this in your ViewController of the scrollView...
- (void) viewDidLoad {
[super viewDidLoad];
UIScrollView * scrollView = self.view;
scrollView.frame = (CGRect){scrollView.frame.origin, CGSizeMake(320, 480)};
scrollView.contentSize = CGSizeMake(320, 1000);
scrollView.backgroundColor = [UIColor whiteColor]; // I am setting the white background, so that the scroll indicator is visible
}
I am assuming you are setting ScrollView as the top view of the ViewController in your Storyboard as in the attached image.
I followed the exact same movie and it did not work for me either. But this movie did: http://www.youtube.com/watch?v=YBlwepYK7Zs
I followed that one and now i got it to work.
A bit late but might be more people looking for a solution to this.
I have a UINavigationController which contains several UIViewControllers. I would like to create a shared "panel" that is displayed at the top of each view. In addition, I would like to make that panel expand and collapse, overlaying the view, when tapped.
View1
-Top Panel (collapsible)
-Main Panel
View2
-Top Panel (collapsible)
-Main Panel
This would be similar to the way the toolbar or navigation panel hide/show for the camera controller, but it would be a custom view. This is an iPhone app.
As a new XCode developer I would appreciate insights as to how this should be approached from an architectural standpoint.
Create a UIViewController subclass, say called PanelStyleUIViewController,
which would be a superclass for all the views that will have the panel. The superclass implements the panel's controller logic, and the view expansion and contraction, which always happens above the children controller's regular view logic.
This is going to be a modestly difficult project for a new iOS/cocoa developer, because:
You probably will end up having to write a lot of the folding panel's view code programmatically. It is possible to design it in interface builder using more advanced techniques but IB's basic usage is to design one view controller at a time. You need to design a partial, parent view controller that then is inherited to a number of different ones.
You need to make sure that the folding view is always above (z-index wise) the regular view content of the lower level view controller classes. This is something that is probably solved by doing a bringSubviewToFront call on the panel view on, say, the viewDidAppear method.
You are going "off road" from how standard iPhone apps behave. Whenever you do this, you make headaches for yourself and might find yourself at a dead end. My recommendation would be to stay "inside the lines" for a while until you are pretty confident with objective C, cocoa touch, etc.
That said, here's some untested code I wrote here in the stack overflow editor which should give you an idea of what I mean for this superclass design:
// PanelStyleUIViewController.h
#interface PanelStyleUIViewController : UIViewController {
UIView *panelView;
}
#property (nonatomic, retain) UIView *panelView;
// PanelStyleUIViewController.m
#implementation PanelStyleUIViewController
#synthesize panelView;
- (void)viewDidLoad {
[super viewDidLoad];
// setup geometry, contents, etc of panelView programmatically...
self.panelView = [[[UIView alloc] init] autorelease];
panelView.frame = CGRectMake(0,0,320,200);
// set resizing mask appropriately for landscape support
panelView.autoresizingMask = UIViewAutoresizingMaskFlexibleWidth | UIViewAutoresizingMaskFlexibleBottomMargin;
// put a button on the panel view so it can be tapped to slide down
UIButton *slidePanelButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
slidePanelButton.frame = CGRectMake(0,160,320,40);
[slidePanelButton addTarget:self action:#selector(slidePanel) forControlEvents:UIControlEventTouchUpInside];
[panelView addSubview:slidePanelButton];
// set panelView with a transform offset to slide it up under the top of the screen
panelView.transform = CGAffineTransformMakeTranslation(0, -160);
// add panelView to regular view controller's view
[self.view addSubview:panelView];
}
- (void)viewWillAppear {
// make sure the panel shows up on top, z-index wise, since subclasses might have created views that overlap it.
[self.view bringSubviewToFront:panelView];
}
- (void)slidePanel {
// remove the panel transform in an animated fashion (slide down).
// TODO: some button or action needs to slide the panel back up...
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];
[panelView setTransform:CGAffineTransformMakeTranslation(0,0)];
[UIView commitAnimations];
}
- (void)viewDidUnload {
[super viewDidUnload];
// always make sure you clean up progammatically-retained views here
self.panelView = nil;
}
- (void)dealloc {
// and here too
self.panelView = nil;
[super dealloc];
}
I'm trying to implement something just like the HeaderFooter sample code that apple provides:
Unfortunately they used Interface Builder to do most of the work here, and I'm beginning to see that interface builder is the hardest thing to deal with in iPhone development.
My table works fine, but the header and footer aren't there at all. My question is how can I make it work.
My code is identical to Apple's, with a few name changes:
- (void)viewDidLoad
{
// headerView
CGRect newFrame = CGRectMake(0.0, 0.0, self.tableView.bounds.size.width, self.headerView.frame.size.height);
self.headerView.backgroundColor = [UIColor clearColor];
self.headerView.frame = newFrame;
self.tableView.tableHeaderView = self.headerView; // note this will override UITableView's 'sectionHeaderHeight' property
// set up the table's footer view based on our UIView 'myFooterView' outlet
newFrame = CGRectMake(0.0, 0.0, self.tableView.bounds.size.width, self.footerView.frame.size.height);
self.footerView.backgroundColor = [UIColor clearColor];
self.footerView.frame = newFrame;
self.tableView.tableFooterView = self.footerView; // note this will override UITableView's 'sectionFooterHeight' property
//...
The problem must be in my xib file, but the sample file has one giant nib that defines everything, all the way back to the window so I can't use that. I had to make my own.
I started with a uitableviewcontroller and nib and added header and footer views views to the nib.
I connected them to their respective IBOutlets in the table view controller subclass.
The delegate and datasource are connected and all the table cells work fine.
What did I forget? Why isn't it making the header and footer?
Follow up question:
How can I learn how to use IB? I try to avoid it, but sometimes I can't. It seems really poorly documented.
It worked when I used initWithNibNamed: to create the view. I'm not really sure why. It seems to use the .nib when I use initWithStyle:. I have to admit, I'm still fuzzy on the relationship between UIViewControllers and .nibs…