im following this ios tutorial:
http://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/SecondiOSAppTutorial/CustomizingDetailView/CustomizingDetailView.html#//apple_ref/doc/uid/TP40011318-CH5-SW3
and im creating a master scene and a detail scene. they are both done as described in the tutorial.
Right now the problem is that when i enter the detail scene, the layout of detail scene is not loaded. instead, a master scene layout with nothing on it is loaded.
So far from what i can see, the problem has to do with transferring the data from master scene to detail scene.
The tutorial does not include this method:
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
without it, the app couldnt go from master scene to detail scene. i think the segue method was suppose to transfer the data and make it go to detail scene, but for some reason it doesnt. so this method was edited to
{
BirdSighting *sightingAtIndex = [self.dataController objectInListAtIndex:indexPath.row];
BirdsDetailViewController *bd= [[BirdsDetailViewController alloc] init];
bd.sighting = sightingAtIndex;
[self.navigationController pushViewController:bd animated:YES];
}
and now the app can go from master scene to detail scene, but the detail scene looks like a master scene with nothing on it.
Any help regarding this or the transferring data between the scenes are greatly appreciated. Thank you in advance.
The point is that the table view selection method doesn't need to be implemented because the selection automatically triggers the segue. If you follow the guide in detail and to the end you will configure the segue and the handling of the segue trigger to configure the new detail view before it appears on screen.
the problem seem to come down to prepareForSegue isnt being called, and just using didselectrowatindexpath isnt transferring the data correctly.
so you can fix it by looking at this answer here:
Custom UITableViewCell not calling prepareForSegue
Seems like when user touch a cell, didSelectRowAtIndex is called, but prepareForSegue isnt. So you need to manually call performSegue for prepareForSegue to work? this is my interpretation.
Related
Im using the Storyboard to create my UI.
I have a SplitViewController. The MasterViewController holds a TableViewController where I created a CustomCell with Custom Design.
The Cells are shown pretty good with my data.
The point is: The Custom Cell also holds an Info-Button, with should Popup a little 300x88 TableViewController with some data.
If the Cells in my MasterViewController->TableViewController where a Static one, I just would drag & drop a Segue from the Info-Button to my Popup-TableViewController.
But sadly I cant do this with a dynamic Prototype Cell... I just get the error:
Couldn't compile connections ... >> anchor >> UIButton...
So how can I implement this?
Kind Regards.
Define a manual segue dragging the whole master view onto the detail view, then add a manual target/action to your custom info button and perform the manual segue there. Of course you must set a segue identifier in the storyboard to later reference it in the code, IB will tell you if you forget to.
Instead of connecting and creating segue from individual cells, you can connect all those segues from the View Controller button, lying below your view in your storyboard. In this case, you will have multiple segues and none of them will be individually connected to cells. And when segues are ready, you can use this method for moving on to the next View Controller depending on which cell is tapped from the tableView.
[self performSegueWithIdentifier:#"yourSegue" sender:nil];
You just have to check which cell is tapped and then perform the appropriate Segue on tap using the above code and the respective segue identifier. The prepareForSegue method will be called immediately after this method is called.
Look out for the yellow button as shown below your View Screen in your storyboard.
Drag and drop a segue from that button onto the View Controller that you want to connect.
Hope this helps.
I have a project utilizing storyboards that uses UITableView in tandem with a Navigation Controller. Its layout is similar to apple's iOS Address Book where there is a table of objects, and clicking on a cell pushes a view onto the navcontroller with that objects's details (properties). I am having trouble using the prepareForSegue method in harmony with the table view's didSelectRowAtIndex. I need a way for the prepareForSegue to know about the row passed in didSelectRowAtIndex so i can pass it's properties to the detail view controller being pushed since prepareForSegue gets called before didSelectRowAtIndex does. If possible I would still like to use the storyboard segue but if there isn't a way i can progamatically push/pop. There is another question similar to this on stackoverflow but it never really was answered, it kind of just rambled on.
If you know a work-around please let me know, thank you!
You can not use didSelectRowAtIndexPath: at all. You can get the index path in prepareForSegue: like this:
UITableViewCell *cell = (UITableViewCell*) sender;
NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
I decided to give the use of storyboards a go in my current iPhone app. I am facing a bit of a problem. I really need to reuse my UIViewController instances.
What do I mean by that? Well, for example I have a table view controller. When I tap a cell, another view controller is loaded from the storyboard and pushed onto the navigation controller stack. This all works well, but it takes about half a second to a second each time this view controller is loaded. Before I was using story boards I simply solved this problem by caching the created instance so the second time you tap a cell the view controller can be immediately shown.
By caching the created instance I mean something like this:
if (!cachedInstance) {
cachedInstance = [MyViewController new];
}
[self.navigationController pushViewController:cachedInstance];
Does anyone know how to accomplish this using the storyboard? Thanks in advance.
If you are using segues, you will need to create custom segues in order to use a cached view controller like you did before. Otherwise, the typical "push" segue will create a new instance of the view controller for segue.destinationViewController. If you write a custom UIStoryboardSegue class and use custom segues you can override initWithIdentifier:source:destination: and put your cached view controller in for the destinationViewController, and then override perform to use the classic pushViewController call.
That is how you handle the segue if you are really intent on using them. I would just skip it though, unless you really want the fancy arrows to lay everything out on your storyboard. If you skip it you can just instantiate the view controllers into the cache and then push them on just like you did before.
If your question is more about locating a view controller inside a storyboard then you can use:
UIViewController *vc = [[UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:#"Some View Controller"];
Then you can save that to your cache and push it like you did in your example code.
Hope that helps.
I'm trying to do something very simple: set up a segue so that when you click on a cell in a table it will take you to another View Controller. The problem, I believe, originates from the fact that the TableView these cells are in is embedded in a regular ViewController (as opposed to a TableViewController), and is one of two subviews in this ViewController.
As far as I can tell, I've set everything up correctly: I embedded the ViewController with the two subviews in a Navigation Contoller, set it to be the dataSource and delegate for the TableView, and created a push segue from a TableViewCell to my second View Controller in the storyboard. However, when the app is run and a user clicks a row in the table, it merely selects the row and the segue doesn't fire at all (I've debugged it and the prepareForSegue function isn't even being called).
Is there something I'm missing here? Or is this for some reason not possible if the TableView is not the only view in its view controller?
I find that if I had recently wired the segue from the cell's accessory view, and later delete the segue and try to wire a new segue to the cell directly it does not work (using Xcode 4.6.2) -- Xcode keeps connecting the segue to the accessory view (even if there isn't one)! The way I fixed it is by selecting the cell in IB and using the connection inspector to (1) delete the original "accessory action" segue and (2) directly wire the "selection" segue by dragging from the filled circle in the image below to the appropriate destination view controller.
This may or may not help you, but I ran into this issue because I had defined two different cell types, and had provided didSelectRowAtIndexPath implementation. I had to add [self performSegueWithIdentifier:#"Whatever" sender:self] as part of didSelectRowAtIndexPath and the issue got resolved.
If you are able to at least detect row selections, you may be able to take advantage of this method.
If you have customized the cell rendering, e.g.:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
then ensure you are using the same cell identifier as specified for the prototype cell in ste story.
So in this case the 'Identifier' of the cell which hooked up the segue should be set to 'Cell'.
If you are creating the StoryBoard in Xcode then do the following:
Create a UITableViewController
Add a prototype UITableViewCell
Create the UIViewController that will be your segue target.
Control-Click on the prototype UITableViewCell and drag to the segue target.
That's it. You'll probably want to edit the characteristics of the UITableViewCell to be, for example, your subclass of UITableViewCell.
I had the similar issue.
Fix is
1. Write SegueIdentifier for the segue in Storyboard
2. Add the following line [self performSegueWithIdentifier:#"SegueIdentifier" sender:nil]; in didSelectRowAtIndexPath.
I hope this would help.
Had the same problem. Segue from a prototype table view cell inside a regular View Controller would make the app crash. In case someone have the same problem.
My solution:
If you are using a push segue make sure your first View Controller with the table view is embedded in a Navigation Controller otherwise "push segues" wont work. Also point the segue at the destination View Controller, not its Navigation Controller!
And as mentioned earlier, make sure your "segue identifiers" are correct.
at "didSelectRowAtIndexPath" I call "[self performSegueWithIdentifier:#"Your_destination_View_Controller" sender:self];
I seem to be having some trouble finding the answer to this one.
My Application loads view controllers using this code:
World_Pick *world_pick = [[World_Pick alloc] initWithNibName:#"World Pick"
bundle:nil];
world_pick.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:world_pick animated:YES];
[world_pick release];
The problem is the previous view isnt being released from memory, and just adding on to it. I have tried stuff like
[self.view removeFromSubview];
[viewController release];
ViewController = nil;
None of which seem to work. Could someone help me?
Thanks
If I understand correctly what you mean, I would say that it is normal, when you present a view controller modally that the underlying view controller is not removed and the view remains there. This is how modal view controllers are presented asa far as I know.
I don´t know what UI you are trying to build into your app, but maybe you should look into using a UINavigationController or, possibly, just adding/removing your views to a base view as need arise. This is of course just a guess, I don´t know what you are trying to do but if you provide more detail, I can help further.
The view controller that's presenting world_pick, the one that's self in the code above, should probably be left alone -- it's presenting a modal view controller, after all, and you'll go back to that view controller when the modal controller is dismissed. The view that it manages should also be left alone. It may be unloaded if there's a memory warning, but if there's memory available it should remain so that it's in place when the modal view controller is dismissed.
Is there some reason you're concerned about this?