views:

75

answers:

3

HI, i am working on a project on which i have to preselect a particular cell. i can per select an cell using willDisplayCell. But i couldn't deselect it while the user click on any other cell.

   - (void)tableView: (UITableView*)tableView willDisplayCell: (UITableViewCell*)cell forRowAtIndexPath: (NSIndexPath*)indexPath
       { 
             AppDelegate_iPad *appDelegte = (AppDelegate_iPad *)[[UIApplication sharedApplication] delegate];

       if([appDelegte.indexPathDelegate row] == [indexPath row])
           {
        [cell setSelected:YES];    
          } 
   }

     -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

        AppDelegate_iPad *appDelegte = (AppDelegate_iPad *)[[UIApplication sharedApplication] delegate];

         NSIndexPath *indexpath1 = appDelegte.indexPathDelegate;

          appDelegte.indexPathDelegate = indexPath;

         [materialTable deselectRowAtIndexPath:indexpath1 animated:NO];
     }
A: 

use this code

  • (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    //Change the selected background view of the cell.

    [tableView deselectRowAtIndexPath:indexPath animated:YES];

}

ksk
@ksk, I have already used that code, But its not works.
Ram
i think u shd set animated to yes in [tableView deselectRowAtIndexPath:indexPath animated:YES];
ksk
@ksk, i dont want to deselect the current cell, i want to deselect the previous one. you can notice my coding. i try to deselect the previous stored indexPath inside appdelegate. AppDelegate_iPad *appDelegte = (AppDelegate_iPad *)[[UIApplication sharedApplication] delegate]; NSIndexPath *indexpath1 = appDelegte.indexPathDelegate; [materialTable deselectRowAtIndexPath:indexpath1 animated:NO];
Ram
+1  A: 

[tableView deselectRowAtIndexPath:indexpath1 animated:NO];

Should work.

Just make sure materialTable and tableView are pointing to the same object. Is materials connected to the tableView in IB?

Jordan
@Jordan i have tested with NO but that also not solve my problem. but i fixed this issue with another way as reloaded Data when ever the didselect delegate fired.
Ram
A: 

Hi,

Please check with the delegate method whether it is correct or not. For example;

-(void) tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath

for: -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

Please check it.

jfalexvijay