-1

I have three tables in a view, I need to implement this kind of structure;

I need to control if the row is selected in the first table, then adding rows of the third table to other view. when i press the button, the data of the selected and the rows in the third table added to view will be sent.

Firstly, i am unable to recognize whether the row is selected or not,

Secondly, when i try just to check it works, my data dictionary sent is empty, that should not.

My code is as below;

-(void) shareComment : (id)sender
{

int ndx = [[tableViewPharmName indexPathForSelectedRow] row];
ProdForLiterature *temp = [pharmsTable objectAtIndex:ndx];

    [sendData setObject:temp.productID forKey:@"ProductName"];
    [sendData setObject:temp.productName forKey:@"ProductId"];

    NSMutableArray *customerId = [[NSMutableArray alloc]init];

    for(DoctorListCell *cell in tableViewDoctorName.visibleCells)
    {
        if([cell.plusButton isHidden])
        {
            if(cell.customerId!=nil)
            {
                [customerId addObject:cell.customerId];

            }
        }

    }

    [sendData setObject:customerId forKey:@"CustomerId"];

  }
erdemgc
  • 1,701
  • 3
  • 23
  • 43

1 Answers1

1

For the first question. To know if a row is selected you can use this method.

NSIndexPath *path = [tableView indexPathForSelectedRow];
int rowSelected = path.row

For the second question, try first logging the temp object to see if it is empty.

NSLog(@"temp:%@",temp);

Also, check after this line.

[sendData setObject:customerId forKey:@"CustomerId"];

With another log to see if sendData contains information or it is initialised.

NSLog(@"sendData:%@",sendData);

Let us know what results you get.

Manuel Escrig
  • 2,825
  • 1
  • 27
  • 36
  • i have one item in my table, when i take the NSIndexPath *path = [tableView indexPathForSelectedRow]; int rowSelected = path.row it is zero, if i take it again without selecting the row physically it is again zero, how to difference between – erdemgc Sep 03 '13 at 12:14
  • If the user hasn't selected anything, it actually returns nil (Apple's docs: An index path identifying the row and section indexes of the selected row or nil if the index path is invalid.). Remember that sending a message to nil is allowed, and in this case [path row] is returning 0 because path is nil. **Checking that the object returned from indexPathForSelectRow isn't nil should solve the issue.** – Manuel Escrig Sep 03 '13 at 12:22
  • @erdemgc If the answer was useful, please accept the answer so it can help others. Thanks! – Manuel Escrig Sep 09 '13 at 14:46