0

我在 cellForRow 方法中有一个 json 响应对象,如下所示:

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

我在每个用户面前都有一个按钮,这样只有所选用户的详细信息才能通过。所以我通过以下标签来做到这一点:

CellForRow:
{
myAray=json; (now this has the values of all users and myArray is declared in the .h file)
UIButton *b=[[UIButton alloc] initWithFrame:CGRectMake(230,0,40,40)];
[b addTarget:self action:@selector(buttonPressed:withEvent:)forControlEvents:UIControlEventsTouchUpInside];
b.tag=indexPath.row;
[cell addSubview:b];
}
-(void) buttonPressed:(id) sender withEvent: (UIEvent*) event{
UIButton *mybtn=(UIButton*) sender;
NSMutableArray * localArray;
localArray=[myArray objectAtIndex:mybtn.tag];
}

问题:抛出异常并且 localArray 不被打印。

4

2 回答 2

0

你看到这些是不同的 ivars:

myAray=json;

[myArray objectAtIndex:mybtn.tag];
于 2012-09-27T13:19:20.480 回答
0

myArray 可能由 dataType "Dictionary" 组成

试试这个而不是 NSMutableArray *localArray;

NSDictionary *dict =[myArray objectAtIndex:btn.tag];
NSLog(@"%@",dict);
于 2012-09-27T13:20:33.990 回答