ios 6 - Fire segue just after data has been loaded - ios

I have some data in TableView. What I want is to call services just after user tapped on row.
Main problem is that 'performToSegue' is calling first so there is no data to populate in tableView in destination controller.
How can I call segue just after data has been retrieved?
Thanks a lot for suggestions!

You'll need to delete the segue in the storyboard that you dragged from a cell to the next viewController.
Next make a segue by dragging from the current controller to the next controller
Now in the UITableViewController implement
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Do some network request
// on completion call
[self performSegueWithIdentifier:#"theIdentifierUsedInStoryboard" sender:self];
}

Related

TableView cell is not pushing to next view controller

I created the single view application using storyboard.
In storyboard file, i have three view controller
1-navigation controller 2-Recipe Book View Controller 3-View
Controller
Prototype cell of the table view of Recipe Book View Controller is connected through push segue to View Controller.Is the problem Recipe Book View Controller does not navigate to View Controller?
here is the sample of project for download.
https://drive.google.com/open?id=0B5pNDpbvZ8SnLTd1R3NBTE1ReEk
I just Check your project.
Do following steps:-
In Main.storyboard, click on Push segue to ViewController and add name of identifier
Go to ViewController.m and paste below code
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self performSegueWithIdentifier:#"yourSegueName" sender:self];
}
Following mistakes are found in your project.
There is no class for Third VC.
PrepareForSegue not implemented.
You wanted to push VC on TableViewCell selection but there you does not implemented didSelect tableview delegate.
Select the segue connecting RecipeBookViewController to ViewController , Then give that segue an identifier, i.e. "ViewControllerSegue".
Implement the delegate method of table view and call the performSegueWithIdentifier method :
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self performSegueWithIdentifier:#"ViewControllerSegue" sender:tableView];
}
Based on your Source code you have to add some code & classes in your project to achieve your requirement.
1st You have to add RecipeViewController to control your Recipe List and Tableview both.
2nd as You have created this RecipeViewController you need to assign this class to respective ViewController in your storyboard.
3rd Assign Segue from PrototypeCell to ViewController where you need to push.
Hope you can understand whats wrong in your Code.

Segue not working on tableView

Okay, I got this strange situation.
I have multiple tableViews in my project, but only on one tableView I can click on an item and perform an action (go to next segue).
On the other tableViews I can click what I want but nothing happens.
I removed the one that was working and made the link again, and it was still working. What am I missing?
I'd like to suggest to you to use the delegate method to handle item selection:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Here you can do something with, e.g. push a view controller:
id vc = [self.storyboard instantiateViewControllerWithIdentifier:#"myVC"];
[self.navigationController pushViewController:vc animated:YES];
}
In most cases it is more comfortable to implement and maintain table views with delegates instead of using segues.

Table view cell to another view controller

I'm creating a small app with StoryBoard, that currently consist of a Navigation Controller, Table View Controller and a regular view controller. I have an array of objects that is connected to the table view, and now I want to select one of the objects and get the regular view controller on the screen. So, in StoryBoard I CTRL-drag from the prototype to the view controller in order to create a segue (push). Now, I want it to work, but literally nothing happens.
What am I doing wrong? Shouldn't this work directly or am I missing to set some options? I really want this to work with the StoryBoard but I tested to give the segue an identifier and implement the below metod, but that didn't work either.
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
[self performSegueWithIdentifier:#"showInfo" sender:self];
}
for navigating from UITableViewCell, You need to write your "code for navigation" in UITABLEVIEWDELEGATE method,
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// your code for navigation.
}
First, you are using the method tableView:didDeselectRowAtIndexPath:, where it should be tableView:didSelectRowAtIndexPath:. Don't worry, that's something I keep doing from time to time.
Then, make sure your segue's identifier is "showInfo" in your storyboard and you are good to go.

what is the correct approach to push or segue a new view from only one cell of a dynamic tableview

IOS 6 , XCode 4.6.2 using storyboards
Heres my problem. I have a tableview with 7 cells using dynamic prototype. I would like to segue from the third cell to another tableview (which is going to allow the user to select a country and pass that country back.)
Is it possible to set this up so only that one cell triggers the segue ?
If its not, then I presume I would need to use the didSelectRowAtIndexPAth method - but if i haven't drawn a seque in the storyboard i cant call performSegueWithIdentifier because there is no identifier- and no segue
Any ideas what should do ?
Cheers
Simon
Don't draw your segue from the cell prototype in the table. Instead draw it from the Files Owner icon below your table view controller to the next table view controller. Give it an identifier and then call
[self performSegueWithIdentifier:#"yourSegueIdentifier" sender:self];
in tableView:didSelectRowAtIndexPath.
If you don't have a segue between view controllers you can use push methods of UINavigationController.
If you already have a segue between the two view controllers you can do this:
-(void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.row == yourCellIndex) {
[self performSegueWithIdentifier:#"yourSegueIdentifier" sender:objectThatYouSendOrNill];
}
}
If you are using static cells in your table view controller you can directly link segue from your cell to the destination view controller.
You can design the DetailViewController in storyboard itself. Give a StoryboardID for that view controller. and in didSelectRowAtIndexPath
-(void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row == 3)
{
DetailViewController *viewController=[self.storyboard instantiateViewControllerWithIdentifier:#"DetailViewController"];
[self.navigationController pushViewController:viewController animated:YES];
}
}
Dont forget to give StoryboardId for the DetailViewController as DetailViewController

Storyboard segue gets called before UITableView's didSelectRow

I have a storyboard with segue from a table cell. I want to set some properties with some data when a row gets selected so I do the following:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[[ProperyManager sharedPropertyManager]setSelectedRow:[verseIds objectAtIndex:indexPath.row]];
[[ProperyManager sharedPropertyManager]setID:[poemIDs objectAtIndex:indexPath.row]];
[[ProperyManager sharedPropertyManager]setRowToReturn:[NSString stringWithFormat:#"%i",indexPath.row]];
}
The problem is, the view controller lifecycle methods (viewWillAppear etc.) of the destination view controller get called before the didSelectRow method above, because the segue pushes the view before the delegate method is executed.
How can I get around this?
Rawkode's answer is one good solution - an alternative is that, in prepareForSegue:, you can access the selected row of the table view (the sender argument will be the table view cell, you can then do [self.tableView indexPathForCell:(UITableViewCell*)sender] to get the index path) and set up whatever you need at that point.
Don't create the Segue from the Cell to the new VC, instead set the Segue from the old VC to the new VC and give the segue an identifier.
Then within
didSelectRowAtIndexPath you can call
[self performSegueWithIdentifier:#"Segue" sender:self]

Resources