Iphone NSMUTABLEARRY在表视图中显示空值 -(void)viewDidLoad{ self.detailView=[[UITableView alloc]initWithFrame:CGRectMake(0,0320480)style:UITableViewStylePlain]; self.detailView.dataSource=self; self.detailView.delegate=self; self.detailView.multipleTouchEnabled=YES; [self.view addSubview:self.detailView]; [超级视图下载]; self.title=NSLocalizedString(@“Routes”,无); self.detailArray=[[NSMutableArray alloc]init]; NSString*url=[NSString stringWithFormat:@”http://maps.googleapis.com/maps/api/directions/json?origin=Chennai&destination=Madurai&sensor=false"]; NSURL*googleRequestURL=[NSURL URLWithString:url]; 调度异步(调度获取全局队列(调度队列优先级默认为0)^{ NSData*data=[NSData dataWithContentsOfURL:googleRequestURL]; NSString*someString=[[NSString alloc]initWithData:数据编码:NSASCIIStringEncoding]; n错误*错误; NSMutableDictionary*parsedJson=[NSJSONSerialization JSONObjectWithData:数据选项:针织错误:&错误]; NSArray*allkeys=[parsedJson allkeys]; 对于(int i=0;i
我想在表视图中显示detailArray。但它在表视图中显示空值。但在NSlog中显示当前值。detailArray具有一组方向值。在TableView中可以显示任何内容。如果我在displayArray中给定常量值,它将在TableView中正确显示。如果有人知道,请帮助我。我在等待你宝贵的答案,谢谢 更新 在添加整个数据(值)后,保留它并重新加载TableView,如下图所示Iphone NSMUTABLEARRY在表视图中显示空值 -(void)viewDidLoad{ self.detailView=[[UITableView alloc]initWithFrame:CGRectMake(0,0320480)style:UITableViewStylePlain]; self.detailView.dataSource=self; self.detailView.delegate=self; self.detailView.multipleTouchEnabled=YES; [self.view addSubview:self.detailView]; [超级视图下载]; self.title=NSLocalizedString(@“Routes”,无); self.detailArray=[[NSMutableArray alloc]init]; NSString*url=[NSString stringWithFormat:@”http://maps.googleapis.com/maps/api/directions/json?origin=Chennai&destination=Madurai&sensor=false"]; NSURL*googleRequestURL=[NSURL URLWithString:url]; 调度异步(调度获取全局队列(调度队列优先级默认为0)^{ NSData*data=[NSData dataWithContentsOfURL:googleRequestURL]; NSString*someString=[[NSString alloc]initWithData:数据编码:NSASCIIStringEncoding]; n错误*错误; NSMutableDictionary*parsedJson=[NSJSONSerialization JSONObjectWithData:数据选项:针织错误:&错误]; NSArray*allkeys=[parsedJson allkeys]; 对于(int i=0;i,iphone,xcode,uitableview,ios5,nsmutablearray,Iphone,Xcode,Uitableview,Ios5,Nsmutablearray,我想在表视图中显示detailArray。但它在表视图中显示空值。但在NSlog中显示当前值。detailArray具有一组方向值。在TableView中可以显示任何内容。如果我在displayArray中给定常量值,它将在TableView中正确显示。如果有人知道,请帮助我。我在等待你宝贵的答案,谢谢 更新 在添加整个数据(值)后,保留它并重新加载TableView,如下图所示 - (void)viewDidLoad { self.detailView = [[UITableView all
- (void)viewDidLoad {
self.detailView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 480) style:UITableViewStylePlain];
self.detailView.dataSource = self;
self.detailView.delegate = self;
self.detailView.multipleTouchEnabled=YES;
[self.view addSubview:self.detailView];
[super viewDidLoad];
self.title = NSLocalizedString(@"Routes", nil);
self.detailArray = [[NSMutableArray alloc] init];
NSString *url = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/directions/json?origin=Chennai&destination=Madurai&sensor=false"];
NSURL *googleRequestURL=[NSURL URLWithString:url];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSData* data = [NSData dataWithContentsOfURL: googleRequestURL];
NSString *someString = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
NSError* error;
NSMutableDictionary* parsedJson = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSArray *allkeys = [parsedJson allKeys];
for(int i = 0; i < allkeys.count; i++){
if([[allkeys objectAtIndex:i] isEqualToString:@"routes"]){
NSArray *arr = [parsedJson objectForKey:@"routes"];
NSDictionary *dic = [arr objectAtIndex:0];
NSArray *legs = [dic objectForKey:@"legs"];
for(int i = 0; i < legs.count; i++){
NSArray *stepsArr = [[legs objectAtIndex:i] objectForKey:@"steps"];
for (int i = 0; i < stepsArr.count; i++) {
NSLog(@"HTML INSTRUCTION %@", [[stepsArr objectAtIndex:i] objectForKey:@"html_instructions"]);
NSLog(@"############################");
[self.detailArray addObject:[[stepsArr objectAtIndex:i] objectForKey:@"html_instructions"] ];
}
}
}
}
});
}
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(NSInteger) tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section{
return [self.detailArray count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10.0f, 5.0f, 300.0f, 30.0f)];
label.text=[NSString stringWithFormat:@"%@",[self.detailArray objectAtIndex:indexPath.row]];
label.numberOfLines = 3;
label.font = [UIFont fontWithName:@"Helvetica" size:(12.0)];
label.lineBreakMode = UILineBreakModeWordWrap;
label.textAlignment = UITextAlignmentLeft;
[cell.contentView addSubview:label];
[label release];
return cell;
}
我相信你的问题已经解决了……:) 删除
[self.detailView重载数据]代码>来自cellforrowatinexpath
方法。并删除tableView.delegate=self代码>使用相同的方法
记住[super viewDidLoad]代码>必须写入viewDidLoad
的顶部
编辑
只需按如下所示更改您的四个阵列
[self.detailArray retain];
[self.detailView reloadData];
为什么要在viewDidLoad中设置detailView委托和数据源两次。请先格式化代码,然后我们就可以很容易地描述问题了
NSArray *legs=(NSArray *)[dic objectForKey:@"legs"];
NSArray *arr = (NSArray *)[parsedJson objectForKey:@"routes"];
NSArray *legs = (NSArray *)[dic objectForKey:@"legs"];
NSArray *stepsArr = (NSArray *)[[legs objectAtIndex:i] objectForKey:@"steps"];
尝试在向detailArray添加值后立即添加断点,以检查detailArray中是否包含值。还有,为什么要在cellForRowAtIndexPath:
中将委托设置为tableview??还有,为什么要在cellforrowatinexpath:
方法中重新加载tableview??从cellforrowatinexpath:method
tableView.delegate=self中删除这两行;和[self.detailView reloadData];Anila detailArray的值正在更正。我删除了这两行,但没有更改。@Vishnusabalan:::在viewDidLoad的末尾添加NSLog(@“%@”,self.detailArray)
。也[self.detailView-reloadData]
再次调用tableview委托方法。因此,可能是一个无限循环我删除了这两行,但没有更改。请帮助我。打印parsedJson它打印什么?它显示两条路由之间的全部细节。例如:(lat,long,dis,route)。我从中提取路由值并存储在detailArray中。如果它不工作,则还更改NSArray*allkeys=(NSArray*)[parsedJson allkeys];我对所有行进行了更改没有更改。它不会调用方法CellForRowatineXpath。如果我在detailarray中使用常量值,则表示它调用方法CellForRowatineXpath。我删除了这两行,但没有更改。请帮助我。set label.textColor=[UIColor blackColor];并且在每个标签中设置文本测试,尝试一下,这样我想你的方法cellforrowatinexpath
就不用调用了,只需在你的cellforrowatinexpath
方法中添加这一行,并使用NSLog(@“cellforrowatinexpath called”)代码>告诉我这行是否可以打印..它没有打印。如果我在detailarray中给定常量值,则表示它可以打印。是的,则表示您的数组存在问题。。我确信。。只需在像[self.detailArray retain]那样添加值init之后保留该数组;
self.detailView.dataSource=self;
self.detailView.delegate=self;
self.detailView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 480) style:UITableViewStylePlain];
self.detailView.dataSource = self;
self.detailView.delegate = self;