在Tableview中触摸屏幕后显示NSArray值 [英] NSArray Values are Display after touche in screen in Tableview

查看:107
本文介绍了在Tableview中触摸屏幕后显示NSArray值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

- (void)viewDidLoad {
detailView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 330, 380)       style:UITableViewStylePlain];
detailView.rowHeight = 55.0f;
detailView.dataSource =self;
detailView.delegate =self;
NSLog(@"finish0");
[self.view addSubview:detailView];
self.title = NSLocalizedString(@"Routes", nil);
self.detailArray = [[NSMutableArray alloc] init];
url = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/directions/json?origin=%@&destination=%f,%f&sensor=false",start1,center.latitude,center.longitude];
    NSURL *googleRequestURL=[NSURL URLWithString:url];
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSData* data = [NSData dataWithContentsOfURL: googleRequestURL];
        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];
                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++) {
                        [self.detailArray addObject:[[stepsArr objectAtIndex:i] objectForKey:@"html_instructions"] ];
                        string = [self.detailArray componentsJoinedByString:@","];
                         NSLog(@"string%@",string);
                      [self stringByStrippingHTML];
                        self.detail=[string componentsSeparatedByString:@","]; 
                        [self.detail retain];
                        [detailView reloadData];                       
                    }}}}        
    });    
 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(NSInteger) tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section{
    return [detail count];
    NSLog(@"table2");
}   
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
        NSLog(@"table4");
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(5.0f, 0.0f, 300.0f, 60.0f)];
    label.text=[NSString stringWithFormat:@"%@",[detail 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;
}
-(NSString *) stringByStrippingHTML {
NSRange r;
while ((r = [string rangeOfString:@"<[^>]+>" options:NSRegularExpressionSearch]).location != NSNotFound)
    string = [string stringByReplacingCharactersInRange:r withString:@""];
return string;
}

在编码中,触摸后显示self.detail(数组)的值当我进入TableView时,TableView.i中的屏幕需要立即显示值。如果你知道,请任何一个帮助。并告诉我为什么NSArray的值只有在触摸或滚动tableview后才显示。

In The coding the values of self.detail(array) display after touches the screen in TableView.i need to display the values immediately when i enter the TableView. please any one help if you know. and tell me why the values of NSArray display only after touch or scroll the tableview.

推荐答案

试试这个

    [self.detailView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];

    instead of [detailView reloadData]; 

这篇关于在Tableview中触摸屏幕后显示NSArray值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆