When I load my xib: AboutViewController as a subview of the view contentView, I just get a blank black screen, can someone help??
UIView* moreView = [[[NSBundle mainBundle] loadNibNamed:#"AboutViewController" owner:self options:nil] lastObject];
[_revealView.contentView addSubview:moreView];
You should use view controllers instead, then just access the view of the view controller:
UIViewController * aboutVC = [[UIViewController alloc] initWithNibName:#"AboutViewController" bundle:nil];
[_revealView.contentView addSubview:aboutVC.view];
Alternatively, you may be interested in presenting the view modally:
[_revealView.contentView.viewController presentModalViewController:aboutVC
animated:(BOOL)animated];
If you are not using ARC, you will have to manage aboutVC manually with retain and release.
Related
Helo. I have big problem.
So i have .xib with view (my popover) , tableview and button.
In popover.m i have just static method to load .xib and close button delegate. Popover is not VC
I have to customize my table and load data from DB.I created
TableView.m but i cant drag and drop TableView like outlet.
In addition, I implemented delegate/datasource
Have someone similar problem ? :)
I will be grateful for all the advice
Code from popover.
+ (TaggingAdditionl *) createInstance {
TaggingAdditionl *taggingXibView = [[[NSBundle mainBundle] loadNibNamed:#"TaggingPopOver" owner:self options:nil] objectAtIndex:0];
[taggingXibView setFrame:[UIScreen mainScreen].bounds];
[taggingXibView setBackgroundColor:[UIColor redColor]];
return taggingXibView;
}
- (IBAction)didPressCloseButton {
[self.delegate taggingAdditionDidClose: self];
}
#end
I use the following code:
PBComboBoxDetailsTableViewController *vc = (PBComboBoxDetailsTableViewController *)[self.storyboard instantiateViewControllerWithIdentifier:#"PBDetailListViewController"];
NSString *path = [[NSBundle mainBundle] pathForResource:#"Settings" ofType:#"plist"];
NSDictionary *settingsDict = [NSDictionary dictionaryWithContentsOfFile:path];
vc.dataSource = settingsDict[#"Frequency"];
[self presentViewController:vc animated:YES completion:nil];
And UITableView appears under the status bar and of course I cannot set up its frame manually because it appears as a top view controller and position option is disabled.
Are there ways to solve this problem except of inserting this table into viewcontroller?
If your view controller is of type UITableViewController the view property of this controller, i.e. the top view in the hierarchy is the table view.
If you want your table view to fill any other space than the entire view (screen) you will have to use a UIViewController and add tableView, as well as its delegate and datasource methods manually.
I want to display the contents of a .xib file when a button is pressed in my app. It would be the equivalent of the following in android:
Intent intent = new Intent(myActivity.this,classiwanttogoto.class);
startActivity(intent);
Is there something equivalent to that in Cocoa Touch? I know that it is very easy with storyboards, and if it comes to that I will use it, but I would like iOS 4 support.
You initialize UIViewControllers like so:
MyViewController *viewController = [MyViewController alloc] initWithNibName:#"MyNibName" bundle:nil];
And then you use it.
Or you can initialize a view from a nib:
UIView *myView = [[[NSBundle mainBundle] loadNibNamed:#"MyViewName" owner:self options:nil] objectAtIndex:0];
I have a UIViewController (Main VC) into which another UIView is loaded as subview when a button is tapped on MainViewController. Actually I load a map view as subview in the main view controller. For that purpose I need to pass the coordinate from MainViewController to the subview (map view) to create the annotation there & then loaded inside the MainViewController.
In MainViewController the following method loads the subview correctly:
-(IBAction)showUserLocation{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"UserCurrentLocationView" owner:self options:nil];
UIView *currentLocationView = [nib objectAtIndex:0];
currentLocationView.frame = CGRectMake(8, 10, currentLocationView.frame.size.width, currentLocationView.frame.size.height);
[thirdPortion addSubview:currentLocationView]; // thirdPortion is a View Outlet in the Main VC wh
}
Here I want to pass a coordinate (lat/lon) to the UserCurrentLocationView 's class so that it can prepare the map and I can see the pointed map in the MainViewController when showUserLocation method is called by a button.
What is the way to set the value of a property that stays on the UIView (Subview) from the MainViewController.
Thanks in advance!
You have to subclass the UIView (I will call it YourView) and add a two properties for long and lat. Then put it as the class for your .xib - file named UserCurrentLocationView.
Then you do the following to set the variables.
-(IBAction)showUserLocation{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"UserCurrentLocationView" owner:self options:nil];
YourView *currentLocationView = (YourView *)[nib objectAtIndex:0];
currentLocationView.lon = self.fooValue;
currentLocationView.lat = self.fooValue2;
currentLocationView.frame = CGRectMake(8, 10, currentLocationView.frame.size.width, currentLocationView.frame.size.height);
[thirdPortion addSubview:currentLocationView]; // thirdPortion is a View Outlet in the Main VC wh
}
I've created an almost-empty UIViewController class named MyViewController. In the viewDidLoad I'm setting the title and adding a close-button to the navigationItem.leftBarButtonItem.
I'm presenting my MyViewController like this:
MyViewController *myViewController = [[MyViewController alloc] init];
UINavigationController *nc = [[UINavigationController alloc] myViewController];
nc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:nc animated:YES];
When the viewController is presented, the background of it's view is just black. How can I setup it's view to fill-out the screen with an empty view -- just like when the UIViewController is setup in a Storyboard?
I've tried adding the following to the viewDidLoad, but the view is still black:
self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
By default a VC's view gets created in -loadView which you usually neither call, nor override. It gets called automatically the first time you request the the VC's view property.
The view's size is automatically set to the 'empty space', like everything except for the status bar without a NavigationController, minus the navbar when using one etc. You shouldn't worry about its size - usually it's just fine.
You can add your own views in -viewDidLoad and remove them again (for low-memory reasons) in -viewDidUnload.
You can add an UIImageView with custom image and then sent it to back
So in your viewcontrollers viewDidLoad
UIImageView *back = [[UIImageView alloc]initWithImage:[UIImage imageNamed:#"MyBG"]];
[self.view addSubview:back];
[self.view sendSubViewToBack:back];
If you are using a XIB file you should init the view controller through the method initWithNibName: bundle: