mercredi 24 juin 2015

how to disable didselectrowAtIndexPath when switches in tableview accessory type are ON.?

Here is my code for disabling didselectRowAtIndexPath . It disables the did select row when switch is on

But when more than on switch in accessory is on e.g. - if three switches are on and I turn off one switch , then the did select row works.

I want to disable that.

Any help ?

enter image description here

Here is my code.

     - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
       {
       if (switchControl.on) {
       NSLog(@"Switch is on");
       UIAlertView *switchAlert = [[UIAlertView alloc]initWithTitle:@"Switch is On" message:@"Please turn it off to proceed further" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
       [switchAlert show];
       }
        else{
        // table view did select working .
       }

and cellForRowAtIndexPath is -

   -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
     {
      static NSString *cellIdentifier=@"CellID";
      UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];

          if (cell==nil)
         {
   cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
   cell.backgroundColor=[UIColor colorWithRed:238.0/255.0 green:238.0/255.0 blue:239.0/255.0 alpha:1.0];
   switchControl = [[UISwitch alloc] initWithFrame:CGRectZero];
   switchControl.tag = indexPath.row;
   cell.accessoryView = switchControl;
   [switchControl setOn:NO animated:NO];
   [switchControl addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
}}

See more ..

Aucun commentaire:

Enregistrer un commentaire