George
George

Reputation: 352

How to display the selected cell in highlighted state when i come back in UITableView?

I created a custom cell for my table view and for the most part everything seems to be working fine, but when I select one of the rows (which takes me to another UIView), then come back from the subsequent view via the nav controller, the selected cell is not in highlighted state. How to display the selected cell in highlighted state when i come back?

any help is appreciated in advance, thanks.

Upvotes: 1

Views: 278

Answers (2)

kviksilver
kviksilver

Reputation: 3854

As @sachin said, you should save selected index path

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    self.selectedIndexPath = indexPath;
}

and in

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

You should check if indexPath is equal to selectedIndexPath, but you should be aware that Apple discoureges that kind of behavior in HIG: http://developer.apple.com/library/ios/#DOCUMENTATION/UserExperience/Conceptual/MobileHIG/UIElementGuidelines/UIElementGuidelines.html

In rare cases, a row might remain highlighted when secondary details or controls related to the row item are displayed in the same screen. However, this is not encouraged because it is difficult to display simultaneously a list of choices, a selected item, and related details or controls without creating an uncomfortably crowded layout.

Upvotes: 0

Tendulkar
Tendulkar

Reputation: 5540

when you are coming back from anotherview make sure that save the selectedCell and then in viewwillappear method reloaddata.in cellforindexpath write the code of selection style uitableviewcellselectionstyleblue

Upvotes: 5

Related Questions