当在表中选择一行时,在另一个表上执行某些操作?

时间:2013-09-03 09:13:55

标签: ios uitableview uibutton row nsmutabledictionary

我在视图中有三个表,我需要实现这种结构;

我需要控制是否在第一个表中选择了行,然后将第三个表的行添加到其他视图中。当我按下按钮时,将发送所选数据和第三个表中添加到视图中的行。

首先,我无法识别行是否被选中,

其次,当我尝试检查它是否有效时,我发送的数据字典是空的,不应该。

我的代码如下;

-(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"];

  }

1 个答案:

答案 0 :(得分:1)

对于第一个问题。要知道是否选择了行,您可以使用此方法。

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

对于第二个问题,请先尝试记录临时对象以查看它是否为空。

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

另外,请检查此行。

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

使用另一个日志查看sendData是否包含信息或是否已初始化。

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

告诉我们你得到的结果。