I am currently writing an app that downloads the RSS feed of a wordpress website and displays it in a table view. When you tap on an item in the list, it goes to the details view and displays the content. However, I have a strange issue with the segue to get from the Table View to the Detail View whereby the segue is not performed immediately after tapping on a row, but only when another row is tapped afterwards. The content displayed is that of the first selection.
For example, if i click row 1, it is highlighted but there is no transition. Nothing happens until I click another row, at which point the segue is performed to the detail view which shows the information for row 1. I have the following methods to perform the segue:
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
_selectedFeedItem = _feedItems[indexPath.row];
[self performSegueWithIdentifier:#"detailSegue" sender:self];
}
and
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
DetailViewController *detailVC = segue.destinationViewController;
detailVC.selectedFeedItem = _selectedFeedItem;
}
I am very new to objective-C and iPhone app development so apologies if this is an obvious issue. Any help appreciated. Thanks.
You have...
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
(deselect)
You need...
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
(select)
Related
I have a UITableViewController that I display modally. When the user clicks on any cell, I need to capture that choice and dismiss the view controller. The weird thing is that the first cell that is clicked is not recognized. When the user clicks on another cell, that is recognized and everything works as intended. Obviously, I need the first click to be the one that is recognized. What am i doing wrong?
- (void) tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(#"cell clicked");
// capture user selection and return to previous screen
[self dismissViewControllerAnimated:YES completion:nil];
}
You are using tableView:didDeselectRowAtIndexPath: instead of tableview:didSelectRowAtIndexPath: ;)
EDIT: I have fixed this problem. The code is corrected to show this fix.
I have an app that uses a UITableViewController that displays a list of all 50 states separated into sections alphabetically. I have added the detail disclosure button to the prototype cell in the storyboard and the table displays all the correct information.
When I press the button on a cell, it should segue to a new viewController and display the name of the state as the view title and then display a picture of the license plate in the view.
I am using the -(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath method to control the button press and then I am using the -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender to control the values being passed to the new viewController.
The problem I am having is that when I press the detail disclosure button nothing gets passed. NSLogging the values in the new viewController outputs (null), (null) and the view has no title or picture. However, when I press back and then press the same cell's detail disclosure button a second time, it works like it should. The title is correct and the picture displays properly.
The same is true when I choose another cell, the viewController displays the last information sent and I have to press back and then choose the cell again for it to update. When choosing a different cell for the first time, (null, (null) is what the NSlog is outputting. So I believe what is happening is that the first time a detail disclosure button is pressed, no values are passed, but the second time it is pressed, the values are being passed.
Here is the relevant code:
-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
//Don't even use this method now.
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
UITableViewCell *cell = (UITableViewCell*)sender; //Added this line
self.path = [self.tableview indexPathForCell:cell]; //Added this line
if ([segue.identifier isEqualToString:#"stateSegue"])
{
self.controller = segue.destinationViewController;
self.controller.stateName = [self.stateArray[indexPath.section][indexPath.row]stateName];
self.controller.licensePlateURL = [self.stateArray[indexPath.section][indexPath.row]licensePlateURL];
}
}
Any help with this would be greatly appreciated.
Check which method fires first. Maybe you set properties after segue is performed.
There's no informations about how (when) do you perform segue.
You could add this line to your accessoryButton method:
[self performSegueWithIdentifier:yourIdentifierFromStoryboard sender:self];
I have designed a table view of various books in sections according to their type.If user touches on cell ,a segue is performed to a new view controller which needs a book item.I have initialised this book in
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
method.But after a touched is method is not called first,the following method is called first!!!!
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
What is is the first method called after touching a table view cell....?
I think you have to link segue not with cell but with view of the current view controller. In such case when you click on cell
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
will not be called.
Then in
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
you can manualy perform segue:
[self performSegueWithIdentifier:#"MySequeIdentifier" sender:self];
I have some issue when doing the segue with some data to to another view.
I have a contact book, first tableview is displaying contacts correctly, also with images
While I click on contact it should perform segue to another tableView. But from some reason it takes only first contact (seems like it's not in a loop).
I have one class for contacts and second ViewController. I can't understand why it happens
I created "pastie" link:
Here is the link to My code, to save place
I checked your code and I think that the problem is when the prepareForSegue is called the selected row is already deselected from didSelectRowAtIndexPath. I think that the best approach here is to send the selected index path from didSelectRowAtIndexPath into performSegue method something like:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self.contTableView deselectRowAtIndexPath:indexPath animated:YES];
[self performSegueWithIdentifier:#"NextTable" sender:indexPath];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:#"NextTable"]) {
NSIndexPath *indexPath = (NSIndexPath*)sender
contact = self.contactsToShow[indexPath.row];
[segue.destinationViewController setPhoneNumbers:contact.numbers];
}
}
In order for this approach to work you must link the segue between view controllers not between cell and table view controller.
The Problem is line 196: You wanna have the index path for the selected row. But because in line 215 you are deselecting the cell immediately after being selected, the index path is always 0.
I have created a popover, containing a table
when user will select the row at that time I want to dismiss popover.
any Idea.
Have a look in the apple documentation... Have a look at the popoverclass...
When your table delegate method gets called, close the popover:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[popoverController dismissPopoverAnimated:YES];
// Handle the row click
}
Where popoverController is an instance variable set up when you created the popover.