0

我有一个 NSDictionary json 响应对象,它在调用服务 URL 后打印。

Looks like this:

{
geofenceType="a";
resourceType="b";
requestType="c";
monitoringType="d";
},
{
geofenceType="a1";
resourcetype="b1";
requestType="c1";
monitoringType="d1";
}, ...and so on for different users.

现在我在 tableViewController 中每个用户前面都有一个按钮,按下按钮时,我需要调用另一个服务 URL,该 URL 将 geofenceType 和该用户的 requestType 作为参数。你能帮助我如何传递参数吗?

4

2 回答 2

0

首先给每个单元格按钮(当在 cellForRowATIndexPath 中创建时)应该分配一个标签。应该是 indexPath.row。从您的回复看来,您有字典数组。在数据源方法中设置数组。

然后在按钮选择器中..

用这个

NSDictionary *dict = [yourArray objectAtIndex:sender.tag];

最后

NSLog(@"[dict valueForKey:@"geofenceType"]");

应该给你想要的价值

于 2012-09-27T11:20:08.683 回答
0

您可以通过多种方式执行此操作,最简单的一种是在 cellForRow 方法中分配 button.tag 属性:

 - (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    myButton.tag = indexPath.row;
//other code
}

然后,在按钮处理程序中,您可以像这样获取您的项目:

-(void)btnClicked:(id)sender {
    UIButton * btn = (UIButton)sender;
    yourItemForRow = [myDataArray objectAtIndex:btn.tag];

    //use yourItemForRow
}
于 2012-09-27T11:21:12.983 回答