UICollectionview controller to UItableview controller - ios

hi I have a uicollectionview controller with two buttons ,when i click the first button it directly opens uitableview controller(with 2 button) and when i click the second button i want uicollectionview controller to show? how can i do this in storyboard?
i tried this code inside one button but its throwing one exception like "Nib file not found"
table *listview=[[table alloc]initWithNibName:#"listview" bundle:nil];
[self.navigationController pushViewController:listview animated:NO];
{list view is the uitableviewcontroller name ,i assigned this name on uitableviewcontroller title property in right panel of xcode}

"Nib file not found" error makes me reckon that you haven't spelled the .xib's name correctly.
Lets say you have your controller you want to push to.
TableViewController.h
TableViewController.m
And a corresponding xib thats linked with TableViewController.h. (view, IBOutlets, etc).
TableView.xib
Now in your main ViewController we push to TableViewController
TableViewController *controller = [[TableViewController alloc] initWithNibName:#"TableView" bundle:nil];
[self.navigationController pushViewController:controller animated:NO];
Hope this helps.
BooRanger

We can use Story board identifier for moving from uicollectionviewcontroller to uitableviewcontroller
table *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"list"];
[self presentViewController:vc animated:NO completion:nil];
Its working fine

Related

Popover segue not working

I am developing one iPad application using storyboard. In my application i have 2 view controllers(First view controller and Modal view controller). In my first view controller I have one table view with cell containing one button. If I click the button in each cell I need to go to modal view controller. I connected the modal view controller and button by using a segue. Segue is working perfectly when style is modal but I need style Popover. When I am trying to change the segue style popover the storyboard error occurs and compilation failed comes. How can I solve this issue.
Follow the steps in the image. hope I will help you.
If the error is "Couldn't compile connection..." the problem is how XCode handles an outlet inside a dynamic table cell view.
I suggest you 2 alternatives:
1) The error doesn't come if you can use a "static" table view, in this way the table view must live inside a UITableViewController.
2) If you need a dynamic table, subclass the cell view and in your class (say MyUITableCellView) put an outlet:
#property (weak, nonatomic) IBOutlet UIButton *segueButton;
Then in your storyboard create an outlet from the prototype cell (of class MyUITableCellView) to the button inside the cell (do not create the segue in the storyboard, create only the destination view controller).
Then in the "cellForRowAtIndexPath" do the following:
MyUITableCellView *cell = (MyUITableCellView*)[tableView dequeueReusableCellWithIdentifier:#"MyCell"];
/* IMP: Here you should check if button has already this action (reused) */
[cell.segueButton addTarget:self action:#selector(showPopover:) forControlEvents:UIControlEventTouchUpInside];
and then add the action:
- (void)showPopover:(UIButton*)sender
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *secondVC = [storyboard instantiateViewControllerWithIdentifier:#"secondVC"]; // this is the storyboard id
self.popover = [[UIPopoverController alloc] initWithContentViewController:secondVC];
CGRect fromRect = [self.view convertRect:sender.frame fromView:sender.superview];
[self.popover presentPopoverFromRect:fromRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
Hope this has helped.
Have you included the <UIPopoverControllerDelegate> and implemented it? That's easy to forget the first times.
May be you might have not connected the Anchor, put UIView in your Viewcontroller view somewhere with background colour clear and set Anchor point of the Segue to that view.....

How to programatically change views in iOS

In Xcode 4.5 you can change views from a segue, But I want to programatically change views in Mainstoryboard. I Know in Xib. we use this method:
SecondViewController *Second = [[SecondViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:Second animated:YES];
I want to change the view when the user clicks done in the textfield (This code detects if user clicks done):
-(IBAction)hidekeyboard {
[sender resignFirstResponder];
}
You create a segue in your storyboard that goes from the view that has the text field in question and goes to your SecondViewController. You have to assign an identifier to it (also in the storyboard, click on the line connecting the two view controllers), let's call it "segueToSecondViewController". Then, you can manually call the segue using:
[self.storyboard performSegueWithIdentifier:#"segueToSecondViewController" sender:self];
An alternative to segueing is to instantiate the viewController from the storyboard.
First you assign a Storyboard ID to the viewController in the storyboard.
Then you instantiate that viewController, and present it.
MBTagEditorViewController *tagEditor = [self.storyboard instantiateViewControllerWithIdentifier:#"TagEditor"];
[self presentModalViewController:tagEditor animated:YES];

navigation controller get me to tabbar controller in IOS

Well I have read those posts and tutorials but they made me more confused:
url 1
quest 1
quest 2
What i want is to do this:
At the beginning my app, has a table view. when I press a row, it should take me to another view which has tabs.
What I did so far was these:
1) Created a navigation controller , and there is my tableview. When I press a row, a single view opens. In that view (with its own .xib file) I added tab bars items.
You can see pictures here:
But now, I don't know how to make it when pressing a tab bar item, to open a new view. I am trying to embed my view in a controller but I cannot.
2) Then I tried this:
Having my navigation controller as before and I added in storyboard a tabbar controller like in that picture:
But I cannot connect them. My first view is class "SkiCenter" and code I am using is:
SkiCenter *myDetViewCont = [[SkiCenter alloc] initWithNibName:#"SkiCenter" bundle:[NSBundle mainBundle]];
myDetViewCont.ski_center=[centers objectAtIndex:indexPath.row];
[self.navigationController pushViewController:myDetViewCont animated:YES]; // "Pushing the controller on the screen"
[myDetViewCont release]; // releasing controller from the memory
myDetViewCont = nil;
and I get SIGBRT that says something about .nib file for "SkiCenter".
Can you suggest a sollution in either 1 or 2?
just to make it more clear:
Solution 1:
pressing the row gets me to a single uiview named skicentermain. I have added several tabbaritems but I do not know how to make them open new views.
Sollution 2:
Inserted a tabbar controller. Its first tab is SkiCenter. But when pressing the row, I get a sigbart error. it says something about the nib file of SkiCenter.
If you decide to use storyboard you can simply put an identifier to any view controller from attributes inspector and then instantiate it with its id.
UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
[[self navigationController] pushViewController:[storyBoard instantiateViewControllerWithIdentifier:#"ViewControllerID"] animated:YES];
It looks like your declaring your *myDetViewCont incorrectly. You called your nib SkiCenterMain, not SkiCenter. Also, what exactly is on SkiCenterMain? Is that a UITabBarController?
//SkiCenter *myDetViewCont = [[SkiCenter alloc] initWithNibName:#"SkiCenter" bundle:[NSBundle mainBundle]];
SkiCenter *myDetViewCont = [[SkiCenter alloc] initWithNibName:#"SkiCenterMain" bundle:[NSBundle mainBundle]];

From XIB to Storyboard

I got an app with a storyboard and one window in .xib.
From the storyboard to the .xib i move in that way:
ShowDreamNIBController *detailViewController = [[ShowDreamNIBController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:detailViewController animated:nil];
How can i move back from the .xib to the storyboard?
And one more question. Can i send some information when move to the .xib from storyboard? Like i do it throught segues in prepareForSegue method
UPD I got answer about closing .xib. Need answer about sending information.
you can get back to your storyboard by simply dismissing the modal view controller.
Like this:
- (IBAction)backPressed:(id)sender {
[self dismissModalViewControllerAnimated:YES];
}
You should put this method in your ShowDreamNIBController.
As for the second question, you can send back information to the view controller that presented the modal view controller by getting reference to it using delegation.
EDIT:
To "send information to the XIB" do you mean that you want to set information to the view controller that you want to present? If yes, than use this when you present the modal controller:
ShowDreamNIBController *detailViewController = [[ShowDreamNIBController alloc]initWithNibName:nil bundle:nil];
[detailViewController setSomething: something];
[detailViewController setAnotherThing: anotherThing];
[self presentModalViewController:detailViewController animated:nil];
I hope this helps.

IOS Switch view and storyboard not works

I have a problem with switching views. I'm using a simulator with xcode 4.2
Storyboard contains:
NavigationController (initial view controller)
UIViewController which has relationship with the navigation controller
UIViewController (paired with my custom class: ViewEntryImageController) which hasn't got any relationship. Contains a button, a bottom toolbar with some toolbar button.
User come into the UIViewController, where he can see a ScrollView and in ScrollView some images.
Images has a gesture:
UITapGestureRecognizer *recognizer=[[UITapGestureRecognizer alloc]initWithTarget:self action:#selector(openEntryImage)];
[image addGestureRecognizer:recognizer];
[recognizer release];
The openEntryImage function:
(IBAction)openEntryImage
{
ViewEntryImageController *controller=[[ViewEntryImageController alloc]initWithNibName:nil bundle:nil];
controller.modalTransitionStyle=UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:controller animated:YES];
[controller release];
}
When I try to tap the image, the openEntryImage works as well (the effect is correct), but I don't see my ViewEntryImageController view and my buttons, I'm only see a black window.
I try to put a NSLog line into the ViewEntryImageController viewDidLoad function, and it works, so what is the black window and where is my view controller?
When I try to use pushViewController, on the new view I found a navigation toolbar with a back button, but no other controls.
I tried another version, I created a UIViewController class, but now with a xib file. I used it instead of ViewEntryImageController and it works. Why?
I want to use this controller in storyboard too.
The ViewEntryImageController class by itself has no information about how to build the dialog. But you can instantiate your view controller on your own from the storyboard:
UIStoryboard *myStoryboard = [UIStoryboard storyboardWithName:#"StoryboardFileName" bundle:nil];
ViewEntryImageController *controller = (ViewEntryImageController *)[myStoryboard instantiateViewControllerWithIdentifier:#"ViewEntryImage"];
This assumes a storyboard name of StoryboardFileName and that the view entry image controller has an identifier of ViewEntryImage set in the view properties (Attributes inspector, section "View Controller").
Try it like this :
ViewEntryImageController *controller=[[ViewEntryImageController alloc]initWithNibName:#"ViewEntryImageController" bundle:nil];
If you don't use .nib names but rather use storyboards, it's a bit harder. Create a segue from the controller to the ViewEntryImageController controller by holding ctrl and dragging from one view to the other. Click this segue and give it an identifier.
Then use the [self performSegue:#"identifier"]; function to present the next view.

Resources