I've created a sub class of UITableViewController named LoginViewController with the XIB file using XCode. Then I opened the XIB file with IB and set the table's style to grouped. Finally I wrote the following code:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
LoginViewController *loginViewController = [[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:[NSBundle mainBundle]];
[window addSubview: loginViewController.view];
window.backgroundColor = [UIColor blueColor];
[window makeKeyAndVisible];
[window layoutSubviews];
}
I set the window's background color to blue for you to see what the problem is.
I put a link to the screenshot
As you can see in the screenshot the table view is not display correctly because a margin between the bottom of the main window and the table view is being set and I don't know why.
If I don't use the table style grouped the problem does not occur
The UITableView inside your .xib file probably has a negative vertical offset (i.e. y-axis), which would mean you need to adjust the origin (likely to 0,0) and the frame (to, say, 320x400, or whatever your parent view height is).
this is the common problem while working with the IBOutlet...
Try to create a UITableView programatically by writing code for it.
dont do drang and drop...
specify the framesize of UITableView manually in coding...
specify datasource and delegate manually in coding...
you will deffinatly solved your problem...
even if any problem leave a comment...and accept answer by clicking correct sign if you get resolved....
enjoy the day...
Related
For this requirement I used [self.veiw addSubView:myview];
Also I set the screen size for myview.frame=(0,40,320,400);
Header and footer sizes are 320x40.
It's working perfectly but the problem is when I present or navigate the views, it's not working: view size it adjusted like 320x480.
Any ideas what the cause of this problem could be?
firstOption
As i have understood from your question you want to add a view to the top of the current view.
You can try this:
Add something like this to every viewWillAppear function of your ViewControllers.
UIView* myView = [get your view from appDelegate/yourAnyClass];
//and then add to the top of the view
[self.navigationController.view addSubview:myView];
//It will add the view every time to the topView of your app.
Or secondOption:
You can adjust your ViewController's frame.
Apple Doc. and add custom view to window in appdelegate [self.window add subView:yourView];.
Ok I have a view that we will call homeView. When a certain button is pushed on homeView, a UIPopOverController is presented in the following way:
self.studyPicker = [[[StudyPickerController alloc] initWithStudyArray:self.studyArray ViewNum:butto.tag] autorelease];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:self.studyPicker];
_studyPicker.delegate = self;
self.studyPickerPopover = [[[UIPopoverController alloc] initWithContentViewController:navController] autorelease];
[self.studyPickerPopover presentPopoverFromRect:CGRectMake(955,60, 22,10) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
Which works great. I get a nice big popover controller that displays my tableView data just the way I need it. Just as an FYI, in my StudyPickerController viewDidLoad method, I am also setting this:
self.contentSizeForViewInPopover = CGSizeMake(1000.0, 610.0);
Which allows me to make the size of my tableView nice and big. The problem I am experiencing is after I select a row in this first tableView. The navigationController pushes the new view just fine, but then the width of my popover controller gets cut in half! It doesn't make any sense! I have tried everything and can't figure out what is going on. In the new view, called ScreenView, it also has the same code in viewDidLoad:
self.contentSizeForViewInPopover = CGSizeMake(1000.0, 610.0);
An interesting observation that I've made but don't know what to do with is that if I take out the contentForSize code from the Second view in the tableView, or the one that I am trying to push to within the controller, when it pushes, it gets cut in half again, to the width of a standard popover controller you see in like Safari. But adding that code in makes it 2 times as wide, like there are two glued together or something, but it is still more narrow than the original width.
I don't know what's going on here, hopefully someone can help me out!
Thanks
Here is an image of the width it should stay:
And then here it is after it pushes the new view:
For each view you are presenting in the UIPopoverController, set the property
contentSizeForViewInPopover
For example:
myViewController.contentSizeForViewInPopover = CGSize(120.0f, 320.0f);
You will need to account for the size of the UINavigationBar (that you get from the UINavigationBar) inside the UIPopoverController but overall that controls the stretching and contracting of the UIPopoverController.
In my app start delegate I have the following code:
[window addSubview:[myTabBarController view]];
UIImageView *banner =
[[[UIImageView alloc] initWithFrame:CGRectMake(0,381,320,50)] autorelease];
banner.backgroundColor = [UIColor redColor];
[window addSubview:banner];
[window makeKeyAndVisible];
This works as expected. The tab bar is visible and also my UIImageView is visible.
I need to modify that UIImageView everywhere in my app (I have the TabBarController, a NavigationController, UITableView, etc)
For example, I want to change the background color when I click in a UITableCell.
I tried everything: self.window.view.subviews, atObjectIndex, neither seems to get the current background color.
first you do not need an UIImageView if its just to set a background-color. A UIView is sufficient.
to solve your problem, you can keep a reference to the view who's background-color you want to change in you AppDelegate. you can then access you AppDelegate (and the the reference to your view) from anywhere in your app like so:
((YouAppDelegateName*)[UIApplication sharedApplication].delegate).yourViewReferenceProperty
Are you sure you want to do that?
It's usually best to arrange your app so that the only object manipulating a view controller's view hierarchy is that view controller. If other objects want to change something, they either change the data model or send a message to the view controller. So, you might give your view controller a 'backgroundColor' property, and its setter would update the appropriate view. Setting the background color indirectly through the view controller makes it easier to make changes to your view hierarchy in the future and generally keeps things better organized.
Is it possible to use a UINavigationController in such a way that it doesn't use the full window?
I've tried setting it's view's frame as well as adding it's view to another (non-fullscreen) view instead of the window, and neither seems to work.
You cannot directly change the size of a UINavigationController or it's subviews directly, as the UINavigationController automatically resizes them to full screen, no matter what their frames are set to. The only way I've been able to overcome this so far is as follows:
First, create an instance of UINavigationController as you normally would:
UINavigationController *nc = [[UINavigationController alloc] init];
self.navController = nc;
[nc release];
Then, create an instance of UIView, constrained to the size you really want:
UIView *navView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, DESIRED_HEIGHT)];
navView.clipsToBounds = YES;
[navView addSubview:self.navController.view];
[self.view addSubview:navView];
[navView release];
The navView's clipsToBounds property must be set to YES, or the UINavigationController and it's view will still appear fullscreen. Then, add the UINavigationController to that constrained view. This UIView may then be added to the UIViewController's view, as seen above.
The thing to note is that any UIViewController's views that are added to the UINavigationController will all have their content constrained to navView's bounds, not the frame of the subviews added to the UINavigationController, so the content in each subview should be created to properly display for the navView's bounds.
In any case, this technique does work, as I've created an app that successfully uses it. The only other way I've ever gotten this to work is to create a custom navigation controller class from scratch, replicating the functionality of UINavigationController, but without the automatic resizing (which I've also done in the past), and that can be a pain. Hope this helps.
This is my first post ever, although I have been learning an enormous amount from this community. So I wanted to thank you all for this.
My challenge, and the reason I'm posting here, was to take the answer to this question and refactor it for my needs, using iOS5 and storyboards. This solution probably won't work well for older implementations, but I thought I'd post it anyway.
Here's what I ended up with, and it works well (iPad app). This is all set up on my default UIViewController, set as root in storyboard view.
Hope this helps out!
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
/*vars:
rightSideView is the containing view - this is where the UINavigationController will sit, along with it's view stack
myStoryboard is self-explanatory I think
myViewController is identified as in storyboard as "accountView", to be pulled from the storyboard and used as the rootview
*/
//Steps
//Add subview to this controller's view (for positioning)
UIView *rightSideView = [[UIView alloc]initWithFrame:CGRectMake(30, 30, 500, 600)];
rightSideView.clipsToBounds = YES;//this little baby makes sure that the damn navigation bar clips!!
rightSideView.backgroundColor = [UIColor grayColor];//so I can see it
//instantiate view controller for nav controller's root view
UIStoryboard *myStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:[NSBundle mainBundle]];
UIViewController *myViewController = [myStoryboard instantiateViewControllerWithIdentifier:#"accountView"];
//create NavController
UINavigationController *myNavController = [[UINavigationController alloc]initWithRootViewController:myViewController];
//Add navController as one of my child ViewControllers
[self addChildViewController:myNavController];
//Add NavController's view into my constrained view
[rightSideView addSubview:myNavController.view];
//Finally, add right side view as a subview of myself
[self.view addSubview:rightSideView];
}
This might help?
Adding a UINavigationController as a subview of UIView
You could always use the UINavigationBar class directly, and implement the controlling code yourself.
This is hard to answer because it's complicated.
On iPhone, you cannot have a UINavigationController that is shorter than the screen.
So if you'd like to show an ad banner, show it above the bottom toolbar or below the top navigation bar.
On iPad you can have two UINavigationControllers side by side, but in my case, they still take the entire height of the screen. Given the behavior of iPhone I didn't try to modify the height behavior on the iPad.
I have UITabBarController with 2 tabs. One resizes just fine, when StatusBar size changes (emulator "Toggle In-Call Status Bar" menu item). The other one doesn't.
The problematic tab item contains a static view, which dynamically loads one or another view depending on certain things. While getting this setup working I discovered that main tab view did NOT automagically send e.g. viewWillAppear and viewWillDisappear messages to my dynamic subviews.
Apple docs explained this was because dynamically added views were not recognized by the system.
#interface MyTabViewController : UIViewController
{
UIView *mainView;
FirstViewController *aController;
SecondViewController *bController;
}
...
if (index == 0)
{
self.aController = [[FirstViewController alloc]
initWithNibName:#"FirstViewController" bundle:nil];
[self.mainView addSubview:aController.view];
[self.aController viewWillAppear:YES];
}
How can I get StatusBar size changed event into my dynamic subviews? The "didChangeStatusBarFrame" doesn't work, as documented elsewhere.
Have you taken a look at this question?
Also, can we see your App Delegate code using application:didChangeStatusBarFrame:?
You could program a resize yourself, but usually this is done by using "auto resizing masks". (UIView has a property autoresizingMask).
I'm not sure about it but since your were adding those views programmatically maybe you forgot to set the autoresize mask. Without it the view won't resize automatically when the status bar frame changes.
[newView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleWidth];
I hope it helps.