I create a split view project, on the iPhone's storyboard, i drag a bar button item to the navigation right and change the style Add, and i drag a view controller to the storyboard, so i use control-drag to build the link, and change the uiviewcontroller's custom class "AddViewController", when i run the project and push the DetailViewController, it is black view.
And i have input the code on the AddViewController.m
-(void) viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"AddViewController"];
[vc setModalPresentationStyle:UIModalPresentationCurrentContext];
[self presentModalViewController:vc animated:YES];
}
i found the reason
On the my create "AddCreateViewController", i should comment the function.
- (void)loadView
{
// If you create your views manually, you MUST override this method and use it to create your views.
// If you use Interface Builder to create your views, then you must NOT override this method.
}
Related
I'm pretty new to iOS. I'm building an app and am running into an issue. I have a navigation controller with a table view controller atop its stack. When I select a row in that table view controller, what I'd like to see is a collection view with the following:
The nav bar with the name that appears on the selected cell as the navigation item title.
A collection view as the main interface
a tab bar with the collection view, and an imagePickerController
Here's what my code looks like:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NewTabBarController *tbc = [[NewTabBarController alloc] init];
UIImagePickerController *takeAPicture = [[UIImagePickerController alloc] init];
UITabBarItem *tabItem = [takeAPicture tabBarItem];
[tabItem setImage:[UIImage imageWithContentsOfFile:#"CameraIcon.jpg"]];
[tabItem setTitle:#"Take a photo!"];
UICollectionViewFlowLayout *photoFlow = [[UICollectionViewFlowLayout alloc] init];
PhotoCollectionViewController *photoHub = [[PhotoCollectionViewController alloc] initWithCollectionViewLayout:photoFlow];
[tbc setViewControllers:[NSArray arrayWithObjects:photoHub, takeAPicture, nil]];
NSArray *items = [[items accessor] allItems];
Item *item = [items objectAtIndex:[indexPath row]];
[photoHub setItem:item];
[photoHub useLayoutToLayoutNavigationTransitions];
[[self navigationController] pushViewController:tbc animated:YES];
}
Then in my PhotoCollectionViewController implementation I have:
#syntesize item;
- (void)viewDidLoad {
[super viewDidLoad];
UINavigationItem *itemHeader = [self navigationItem];
[itemHeader setTitle:[item itemName]];
UITabBarItem *tabItem = [self tabBarItem];
[tabItem setImage:[UIImage imageWithContentsOfFile:#"itemImage.jpg"]];
[tabItem setTitle:[NSString stringWithFormat:#"Photos of %#", [item itemName]]];
}
My problem is that when I select the cell, The collection view loads, and I can see the cells I have set up in the collection view, but the nav bar item has no title, and the tab bar item has "Photos of (null)" and no image. The "Take a photo!" text appears, but the image does not.
Do you guys have any idea how I can restructure this to make everything flow correctly. I must be doing something wrong in the way I'm utilizing tab and nav controllers.I don't want there to be any tabs until this stage in the app, which is 3 or 4 VCs in already. Should I be using a tab bar controller from the App Delegate onward?
The problem here is that you are pushing tab bar controller onto a navigation controller stack. The view controllers of a tab bar will have a navigation item, but their navigation items aren't shown when the view controller is on screen. Instead, the tab bar controller's navigation item is on screen.
You could use self.tabBarController.navigationItem, but then each view controller will have to modify the navigation item every time it's brought on/off screen, which is really messy.
If you're going to use a UITabBarController, I would recommend either presenting it modally, or having it be the root view controller on your UIWindow. It's tough to get it working right as a view controller in a navigation controller's view controller stack.
Your tab bar item not showing its name is a separate issue. It's because viewDidLoad is getting called before you set your item instance, specifically it's getting called when you call [tbc setViewControllers:[NSArray arrayWithObjects:photoHub, takeAPicture, nil]];
You can confirm this by breakpointing in view did load, where you'll see that item is nil. If you haven't already, you should overload your setItem: method in PhotoCollectionViewController, and have that method also update your UI.
i have UiViewController as a LoginPage if it passed then it should show UITabBarController firstTab's ; the first tab inside UINavigationController as RootView.
how can i present firstTab from Login Page; i tried the following but error show :
Code IOS 7 StoryBoard
-(void)successLogin{
HomeTableViewController *vc =[self.storyboard instantiateViewControllerWithIdentifier:#"RootViewInControllerInFirstTabBar"];
[self presentViewController: vc animated:NO completion:nil];
}
i assume that the view that should appear after the login page should have tabs- with the first tab selected. the frst tab should have the home tableVC, which is also the root controller of a navigation controller, displayed.
[Updated]
According to my understanding of the doc, you'll first create the login page.
On successful login, the screen will navigate to a new controller derived from UITabbarViewController. Navigation to the UITabbarViewController depends on your choice, or you can even replace the view on the login screen(entirely your choice). Now on the derivedViewController you will set the viewcontrollers that you want to display on each tab using the following method of the UITabbarViewController.
- (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated
On the first item of the tab bar, you will create a new controller(for profile) which will be the rootviewController of the UINavigationController.
I'm trying to get a reference to my detailViewController in application didFinishLaunchingWithOptions: method. But here I am faced with a problem.
I have next Views structure is storyBoard (for iPad):
UISplitViewController --> UINavigationController --> UITableViewController --> detailViewController
I created segue with "push" style between UITableViewControllerCell and detailViewController
Screenshot: http://picturepush.com/public/13071076
I'm trying to get a reference to detailViewController in this way:
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
DetailViewController *detailViewController = [navigationController.viewControllers lastObject];
But in result I got reference to my UITableViewController, instead of acceptable
DetailViewController. The navigationController.viewControllers count is 1 but there should be 2 (I think so).
I hope for your help.
Since you created a segue with push style, the detailViewController will only be loaded after you tap on a table view cell. It will not be loaded on the app didFinishLaunchingWithOptions method.
I would suggest you try to make the detailViewController as a property in your table view controller.
#property (nonatomic, strong) UIViewController *detailViewController;
Then in your app didFinishLaunchingWithOptions method, you can access the property:
UITableViewController *tableViewController = [navigationController.viewControllers lastObject];
DetailViewController *detailViewController = tableViewController.detailViewController;
But you will need to avoid using perform segue function and push the detail view controller whenever it is needed with the usual pushViewController method.
[self.navigationController pushViewController:self.detailViewController animated:YES];
I have tabbar + navigation app. I call filterModalController:
[self.navigationController presentModalViewController:filterModalController animated:YES];
It appeared OK. Then I want to push officeController.
[self.navigationController pushViewController:officeController animated:YES];
But officeController didn't appeared. What is wrong?
My understanding is that modal view controllers are not meant to push other view controllers, so you may want to think about the hierarchy of views you are using. Modals are meant to return to the parent view controller. You may need to call
[self.navigationController dismissModalViewControllerAnimated:YES];
before you push the officeViewController.
When I ran into this, I ended up pushing a Navigation controller as the modal view controller, with the 'filterModalController' as the root view controller. Since you already have a navigation controller, this may make things too confusing.
UINavigationController* filterNavController = [[UINavigationController alloc]
initWithRootViewController:filterModalController];
// Display the nav controller modally.
[self presentModalViewController:filterNavController animated:YES];
[locationNavController release];
Then the filterNavController can push your officeController.
in my app i call a UIView and that UIView is like a settings screen in my app and i have buttons in the UIView and my question is how do i add actions to the buttons iv added to the UIViews subview? thanks,
Assuming you're writing code in a view controller for your settings UIView, the UIView is properly bound to the view property of your controller, and you have referenced one of the buttons with a variable button, here is what you would write:
- (void)viewDidLoad {
[super viewDidLoad];
[button addTarget:self
action:#selector(buttonPressed)
forControlEvents:UIControlEventTouchUpInside];
}
- (void)buttonPressed
{
// do things here in response to the button being pressed
}
Another way to write that method is passing in a pointer to the button which was actually pressed, like so:
- (void)viewDidLoad {
[super viewDidLoad];
[button addTarget:self
action:#selector(buttonPressed:) // note the extra colon here
forControlEvents:UIControlEventTouchUpInside];
}
- (void)buttonPressed:(id)sender
{
UIButton *buttonWhichWasPressed = (UIButton *)sender;
// now you can do things like hide the button, change its text, etc.
}
Rather than calling addTarget:action:forControlEvents:, though, in Interface Builder (you should be doing this) after defining the buttonPressed or buttonPressed: method above, in the .xib file with the button go to the second tab in the Inspector after clicking on the Button (it should say Button Connections), and click-drag the Touch Up Inside event to File's Owner, and select "buttonPressed" from the list.