Weird problem with iPhone UITableView cell not un-highlighting after clicking - iphone

I have an app I am working on, that has a table view with a few cells, and when you hit a cell, the nav controller pushes a new view. Pretty simple stuff. The problem is that when I hit on a row, the whole row highlights blue, and then remains blue all while the view is being presented by the controller, and then if I hit back to go back to the table view, the row is just still completely highlighted Even though I'm not pressing it or anything.
I have made a few apps with the table view before, and have never seen this behavior before, so I am at a loss as to what is going on. Is there some setting that I have set wrong somewhere?
Thanks

You need to deselect cell manually (probably in tableView:didSelectRowAtIndexPath: method):
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
// Your code
...
}

If your view controller is a subclass of UITableViewController, it will automatically deselect the row after you hit the back button. If you don't subclass UITableViewController, you need to call deselectRowAtIndexPath:animated: when you want it deselected.

Related

TableView delegate method called only after a second cell is selected

I'm dealing with a problem that is really making me crazy. I've got a table view added to a view using IB. This tableView has a delegate and a datasource. The delegate is the view controller, the data source is another class that packs information for displaying them. The data source works and fill the table with correct data.
I'm not able to say the same for the delegate. The delegate implements the classic - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath and I have an NSLog inside that method that logs the cell selected.
The problem is that if I selected a cell, the cell changes its color in blue(selected state), but it doesn't trigger the delegate methods. If I press another cell now the new selection on a new cell pushes the detailviewcontroller with the right informations.
If I pop the cell is deseleted- since in viewWillAppear I put a method for deselect selected cell-, if I press a cell again nothing happens just blue selection,if I press another one it pushes the detail view.
I tried to make few changes to make the case easy as possible:
.used default styled cells
.added the tableview programmatically
.check the delegate of the tableview in different part of the code
Everything seems right I really can't understand.
Use
(void)tableView:(UITableView *)tableView selectRowAtIndexPath:(NSIndexPath *)indexPath
instead of
(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath

Detail Disclosure Button and Segues

I'm using a UITableViewController that performs an action sheet upon click, which works great. I'd like to tie the Detail Disclosure to a segue. I created a segue from the cell to the next table, and added the following code:
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:#"GroupToGroupMembers" sender:self];
}
Works great when I tap the Detail Disclosure.
Problem is, tapping on the cell now causes both the action sheet AND the segue to fire off, which I would expect.
Anyone figure out how to fire off a segue off of a detail disclosure only?
You probably have the "GroupToGroupMembers" segue hooked up to your UITableViewCell. When you do this, the segue is automatically performed when the cell is selected. This happening in addition to your regular event handling which is showing the action sheet.
Hook your segue up to your UITableViewController instead. This allows you to define your segue so that it may be performed in response to the DetailDisclosure being tapped while, at the same time, preventing the segue from being automatically performed when a cell is selected.

How would I make a tableview lead to a page which had another tableview?

I want to make a tableview; when you press a cell it takes you to another tableview. If you press a cell on the second table, it takes you to another view. Then, you could go back if you want or whatever. How would I do this? I can make a tableview lead to a new view already, but the real question is how to make another tableview and lead to another view.
I'm not sure if I follow..
Anyhow, I recommend you create a UINavigationController and set the rootViewController to your tableView's controller view property, when a cell is tapped in your tableview you should implement:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
where you would create an instance of another view controller that holds your desired "different" tableview obviously and push it to the navigation controller.
I recommend you take a look at the view controllers programming guide as well as tableviews. It isn't that complex.
The key idea is to know that this behavior you want is basically how the navigation controller works by pushing and popping views.
If you implement it this way (which is what you should be doing) you get lots of functionality for free, such as the behavior when tapping on the "back" button.
Hope it helps.
Do you want to use both tables in the same view controller or do you want to use navigation controller to navigate to the next table view? If you want to use both the tables in the same view controller then differentiate them by tag value.

Issue with deselectRowAtIndexPath in tableView

I have a cell with a few lines of text which changes colour when selected/highlighted. The problem is that as the new viewController is being pushed, the deselection animation occurs which is visually distracting as the text suddenly reverts to the unselected state. I have moved the deselectRowAtIndexPath statement after the line where the new view controller is pushed, but this has no effect.
How can I prevent the user seeing the cell deselection (without implementing a timer)? Any help would be appreciated please.
If you're using a UITableViewController, you won't need to call deselectRowAtIndexPath:. This will be done for you automatically when your table view becomes visible again.
If you're not using a UITableViewController because you have a more complicated interface, you would need to call deselectRowAtIndexPath: manually from the viewWillAppear:animated: method.
I think the general paradigm used with table views and pushing new VCs is that you deselect the table row in your viewWillAppear:animated method. Then as the VC is popped, they see which row had been used to navigate to that VC.
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.myTableView deselectRowAtIndexPath:[myTableView indexPathForSelectedRow] animated:YES];
}
so remove deselectRow from your didSelectRowAtIndexPath method.

UITableView cells do not stay selected when pushing a view

I have a UITableView on a view. This UITableView has cells which are made up of a checkbox custom control, a label and a disclosure accessory. When I select a row in the tableview it selects correctly (blue highlight shows 100% correctly).
I then created a didSelectRowAtIndexPath delegate to push a detail view controller onto the navigation stack using the following code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
MyDetailsViewController *detailsViewController = [[MyDetailsViewController alloc] initWithNibName:#"MyDetailsView" bundle:nil];
[[self navigationController] pushViewController:detailsViewController animated:YES];
[detailsViewController release];
}
This works - in so far as that it pushes the view controller onto the navigation stack and presents the view. The problem I'm having is that the animation is really "flickery" and the row that was selected doesn't even get highlighted before the animation starts.
I've done this before (but never with custom cells) and I know that the procedure should be as follows: row highlights, detail view animates in, (edit details), detail view animates out, row gets deselected.
I'm not sure why my row automatically gets deselected (or de-highlighted) when I select it and why the animation is flickery.
Has anyone had this before?
Ugh, I so hate it when I find the answer to my own question about a minute after posting it. The problem was that I was doing all kinds of things in viewWillDisappear that was modifying my table data. ****grin****