tags:

views:

38

answers:

2

i have all that data with me in tableview but when i dont know how to transfer these values on section view when user press any cell

this is how i am getting values [[jsonArray objectAtIndex:indexPath.row] objectForKey:@"number"];

now how to transfer these values to section

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


        }
+1  A: 

Define a property on your DetailViewController to hold the data, and pass it to that before pushing the view controller onto the navigation stack. Equivalently, add an extra parameter to the view controller's constructor. So given:

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

either do:

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

or:

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

Then you can access your data from within the detail view controller. To add this property, you can do this:

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

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

This means that your DetailViewController now has API for being told about the object it's representing.

Graham Lee
but jsonArray is defined in tableview not in detailview so i cant access from detailview can you explain more about id detail?? you mean in detailViewController--> viewdidLoad() i have to define id ??
prajakta
Yes thats working perfectly fine but my dataObject is having these values { home = sdfsdfdsf; number = "212 555-1234"; type = home;} so how to catch each of them like dataObject.number or so in section view so that i can display them in different cells ??
prajakta
Got it wow perfect Thanks a Lot :-)
prajakta
A: 

to Access indivudal item you can do something like this for those who might want this

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


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

thanks

prajakta