在iphone上使用JSON如何将数据从表视图传递到节视图

在iphone上使用JSON如何将数据从表视图传递到节视图,iphone,Iphone,我在tableview中有所有的数据,但当用户按下任何单元格时,我不知道如何在截面视图中传输这些值 这就是我获得价值的方式 [[jsonArray objectAtIndex:indexath.row]objectForKey:@“number”] 现在,如何将这些值传递到第节 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

我在tableview中有所有的数据,但当用户按下任何单元格时,我不知道如何在截面视图中传输这些值

这就是我获得价值的方式 [[jsonArray objectAtIndex:indexath.row]objectForKey:@“number”]

现在,如何将这些值传递到第节

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell;
    static NSString *CellIdentifier = @"Cell";







   cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil ) {

        NSLog(@" inside");
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];



        mainLabel = [[[UILabel alloc] initWithFrame:CGRectMake(10.0, 5.0, 220.0, 15.0)] autorelease];

        mainLabel.tag =33;

        //  mainLabel.font = [UIFont systemFontOfSize:14.0];
        [mainLabel setFont:[UIFont boldSystemFontOfSize:[UIFont smallSystemFontSize]]];

        mainLabel.textAlignment = UITextAlignmentLeft;

        mainLabel.textColor = [UIColor blackColor];
        mainLabel.highlightedTextColor = [UIColor greenColor];

        //mainLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight;

        [cell.contentView addSubview:mainLabel];
        mainLabel.backgroundColor=[UIColor clearColor];


    }
//  NSDictionary *itemAtIndex = (NSDictionary *)[jsonArray objectAtIndex:indexPath.row];
    //[cell setData:itemAtIndex];

    mainLabel.text = [[jsonArray objectAtIndex:indexPath.row] objectForKey:@"number"];
    NSLog(@" dicst 5@",stream);
            cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
                return cell;

}






- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
            // Navigation logic -- create and push a new view controller
            NSLog(@" push");

//**[[jsonArray objectAtIndex:indexPath.row] objectForKey:@"number"];**  how to do this so i can access from section view 

            aDetail = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:[NSBundle mainBundle]];



            [self.navigationController pushViewController:aDetail animated:YES];

            [aDetail release];


        }

DetailViewController
上定义一个属性来保存数据,并在将视图控制器推到导航堆栈上之前将其传递给该属性。等效地,向视图控制器的构造函数添加一个额外参数。因此:

id detail = [[jsonArray objectAtIndex:indexPath.row] objectForKey:@"number"];
或者:

aDetail = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:[NSBundle mainBundle]];
aDetail.dataObject = detail;
或:

然后,可以从局部视图控制器中访问数据。要添加此属性,可以执行以下操作:

@interface DetailViewController : UIViewController
{
  //...
  id dataObject;
}
//...
@property (nonatomic, retain) id dataObject;
@end

@implementation DetailViewController
@synthesize dataObject;
//...
@end

这意味着您的
DetailViewController
现在有了API,可以告诉您它所表示的对象。

要访问indivudal项目,您可以为可能需要的人执行类似操作

jsonItem=dataObject;// where jsonItem is a NSDict
    NSLog(@" v %@",jsonItem);// all data


    jsonLabel.text = [jsonItem objectForKey:@"type"];// this is how you can display them 

谢谢

但是jsonArray是在tableview中定义的,而不是在detailview中定义的,因此我无法从detailview访问。您能解释更多关于id详细信息吗??你的意思是在detailViewController-->viewdidLoad()中,我必须定义id??是的,这工作得很好,但是我的dataObject有这些值{home=sdfsdfdsf;number=“212 555-1234”;type=home;},那么如何在剖面视图中像dataObject.number这样捕捉它们,以便在不同的单元格中显示它们呢??
jsonItem=dataObject;// where jsonItem is a NSDict
    NSLog(@" v %@",jsonItem);// all data


    jsonLabel.text = [jsonItem objectForKey:@"type"];// this is how you can display them