I have created an UIView which has several controllers , is there any possible way to add this view in UIPopoverController because UIPopoverController just support ViewController !
Create a UIViewController and assign your UIView to be it's .view property. Then you can pass it along to the UIPopoverController while creating it.
Related
I have a UITableViewController and I need to resize the table vertically.
I can't use a UIViewController with a table inside.
There is a method?
Thanks!
This is only possible if your UITableViewController view is manually added to another superview. However, if you are planning to use the table view in a navigation controller or as a modal sheet you do not have control over the table view's size.
To have full control over the table view size:
Make you own subclass of UIViewController with UITableView outlet and a resource file.
Place a UITableView on top of its content view and resize it accordingly.
Make your view controller implement UITableViewDataSource and UITableViewDelegate protocols.
Connect outlets.
Instead of using a UITableViewController, it may be easier just to use a standard UIViewController, with a UITableView property.
E.g.:
#interface ContentsPopover : UIViewController <UITableViewDelegate, UITableViewDataSource>
//...
#property (nonatomic, strong) UITableView *theTableView;
//...
#end
That way, inside your UIViewController you can have the following code (possibly in viewDidLoad):
theTableView = [[UITableView alloc] initWithFrame:/*...*/ style:UITableViewStylePlain];
theTableView.delegate = self;
theTableView.dataSource = self;
theTableView.scrollEnabled = YES;
[self.view addSubview:theTableView];
// You can now change theTableView's frame property as needed
This is handy for when a UITableViewController wasn't quite what you're looking for.
I have 2 UIViews both with a bit off code in them.
I can subclass one to a UIViewController like this self.view addSubView:_msgView];
_msgView being a UIView.
Now _msgView is a Plain UIView that has a 0.7 Alpha to lay over the UIViewController.
now I have another UIView called menuButtons and I want to put that on top of the _msgView.
I was thinking I could use [_msgView addSubView:_menuButton]; but that does not work and gives a warning
Incompatible pointer types sending 'MenuButtons *__strong' to parameter of type 'UIView *'
How do I put a UIView on top of another UIView?
//EDITS:
#import <UIKit/UIKit.h>
#import "SlideMessageView.h"
#import "definitions.h"
#interface MenuButtons : UIView
{
UIButton *onBack;
UIButton *onForward;
UIButton *onRefresh;
UIButton *onHome;
UIButton *onSafari;
UIButton *onChrome;
UIButton *onPocketReader;
UIButton *onSavePDF;
UIButton *onPrint;
UIButton *onShare;
SlideMessageView *msgView;
BOOL viewVisible;
}
The UIButtons have their #properties set below that.
you do 1 thing.. if u are generating both the views through code then add both views in self.view itself and set their frames separately.
i.e if 1st view is at top set the frame msgview.frame = CGRectMake(0,0,320,100);
ans for second view someview.frame = CGRectMake(0,100,320,200);
My problem is I can't show inherited class from UITableViewController with static cells. I am using storyboard for easy custom cells setup (I want to get a Settings App like behavior) in UITableViewController. But I need to nest it in another UIViewController which shows custom top bar (like navigation bar panel). So when I load my UITableViewController with this structure:
#import <UIKit/UIKit.h>
#interface MyCoolTableVC : UITableViewController
#end
I get no issues, all custom cells which I set in storyboard builder are shown in proper way in grouped table view. But when I am using subclass from UITableViewController:
#import <UIKit/UIKit.h>
#import "MyCoolTableVCSubclass.h"
#interface MyCoolTableVC : MyCoolTableVCSubclass
#end
I get this result:
which shows wild appearance of tableView, without sections and custom cells.
I load my controller with this code, if it helps:
UIViewController *vcToGo = nil;
UIStoryboard *storyBoard = [[UIStoryboard storyboardWithName:#"MyCoolStoryboard" bundle:nil] init];
vcToGo = [storyBoard instantiateViewControllerWithIdentifier:#"profileTable"];
[self.navigationController pushViewController:vcToGo animated:YES];
To use static cells, the datasource of the table view has to be set to a UITableViewController subclass, and you must not implement the datasource methods yourself.
The base UITableViewController provides everything to the table view in its own implementation of cellForRowAtIndexPath etc, using what you have put in the storyboard. So if your datasource does not inherit from UITableViewController, it will not be able to populate the table.
(note - This is what I assume is happening based on my own experiments, the internals of UITableViewController are not available to me)
I have a UIView subclass with a drawRect method. My viewController uses this subclass (I just set it in the xib), and so UIView draws a rectangle to the screen fine.
Now, I'd like to send a bunch CGRects stored in my viewController to my UIView drawRect method.
I'm unsure how to pass them. Any ideas? Thanks.
You can add properties to your UIView subclass to store the CGRect's, set them from your UIViewController then call [self.view setNeedsDisplay]; from your UIViewController.
I have subclassed UIView and created a NIB that controls the main logic for my application.
Hoping the view will scale nicely, I want to use it for both the iPhone and iPad versions of the app.
On the iPhone the view will cover the full screen. On the iPad the view will cover only part of the screen.
I have read that you shouldn't use UIViewControllers to control only part of the screen. So, I am trying to embed the custom UIView in the main UIViewController's view using IB.
How can this be done?
After a lot of trial and error I found a solution based on an approach explained in the following question, answered by Brian Webster.
The solution was originally suggested for a Cocoa environment. I hope it is valid in an iOS environment as well.
Create the main view controller with a NIB-file. In the NIB, the File's Owner should correspond to the class of your main view controller.
Create a custom view controller with a NIB-file. In this NIB, the File's Owner should correspond to the class of your custom view controller.
Create a custom view controller property in your main view controller class.
Create an UIView property in the main view controller class. It will hold your custom view controller's view. Define it as an IBOutlet, so it can be linked in the NIB.
Drop a UIView in your main view controller's NIB. Link it to the main view controller's view IBOutlet. It will be used as a placeholder for the custom view.
In the main view controller's viewDidLoad method, load the custom view controllers NIB, determine the custom view's frame size and copy the view in the main view controller's view.
Here is some code:
MainViewController.h
#interface MainViewController : UIViewController {
CustomViewController *customViewController;
UIView *customView;
}
#property (nonatomic, retain) CustomViewController *customViewController;
#property (nonatomic, retain) IBOutlet UIView *customView;
#end
MainViewController.m
- (void)viewDidLoad {
CustomViewController *controller = [[CustomViewController alloc] initWithNibName:#"CustomViewController" bundle:nil];
self.customViewController = controller;
[controller release];
customViewController.view.frame = customView.frame;
customViewController.view.autoresizingMask = customView.autoresizingMask;
[customView removeFromSuperview];
[self.view addSubview:customViewController.view];
self.customView = customViewController.view;
[super viewDidLoad];
}
Add an IBOutlet propertyfor your custom UIView to the UIViewController, and additional outlets for any subviews you wish to access.
Go to Interface Builder, select the "File's Owner" object in your NIB and in the Inspector go the rightmost tab set its class to match your UIViewController's class.
Connect the IBOutlet from step one on the "File's Owner" to your custom UIView.
In XCode, when you need to load your view, do something like this:
--
[[NSBundle mainBundle] loadNibNamed:#"MyNib" owner:self options:0];
self.myCustomView.frame=self.view.bounds; // make view fill screen - customize as necessary
[self.view addSubview:self.myCustomView];
When you load the NIB, the outlet(s) you set up in step 1 will be populated with the objects loaded from your NIB.