我在tableview中拥有所有这些数据但当我不知道如何在用户按任意单元格时在剖面视图上传输这些值
这就是我获得价值的方式 [[jsonArray objectAtIndex:indexPath.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];
}
答案 0 :(得分:1)
在DetailViewController
上定义一个属性以保存数据,并在将视图控制器推入导航堆栈之前将其传递给该属性。等价地,向视图控制器的构造函数添加一个额外的参数。所以给出:
id detail = [[jsonArray objectAtIndex:indexPath.row] objectForKey:@"number"];
要么:
aDetail = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:[NSBundle mainBundle]];
aDetail.dataObject = detail;
或:
aDetail = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:[NSBundle mainBundle] dataObject: detail];
然后,您可以从详细视图控制器中访问您的数据。要添加此属性,您可以执行以下操作:
@interface DetailViewController : UIViewController
{
//...
id dataObject;
}
//...
@property (nonatomic, retain) id dataObject;
@end
@implementation DetailViewController
@synthesize dataObject;
//...
@end
这意味着您的DetailViewController
现在有API可以告知它所代表的对象。
答案 1 :(得分:0)
要访问单个项目,您可以为可能需要此项目的人执行此类操作
jsonItem=dataObject;// where jsonItem is a NSDict
NSLog(@" v %@",jsonItem);// all data
jsonLabel.text = [jsonItem objectForKey:@"type"];// this is how you can display them
感谢