从表视图推送到包含tabbar的视图时,无法在webview中分配数据

时间:2012-02-10 03:54:19

标签: iphone objective-c xcode ipad

我正在解析一个json对象并在表视图中填充它。

当选择表视图行时,它会导航到名为“ThirdDetailView”的详细视图控制器,并能够在我的ThirdDetailView中分配已解析的数据(使用Web视图)。

当我的ThirdDetailView是我的四个标签栏中的一个视图时出现问题。我已将这四个标签栏放在名为firstView的视图中,因此单击tableview导航到包含四个标签栏的firstView,其中显示的ThirdDetailView突出显示为第一个选项卡。如果是这种情况,数据未在Web视图中加载。

下面是代码:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
     title=[story objectAtIndex:indexPath.row];
 NSDictionary *detaildesc1=[media1 objectAtIndex:indexPath.row];
  ThirdDetailView *detailViewController1= [[ThirdDetailView alloc]init];
    [detailViewController1 initWithItem:detaildesc1 Title:title];

     FirstView *dvController4 = [[FirstView alloc] initWithNibName:@"FirstView" bundle:[NSBundle mainBundle]];
    [self.navigationController pushViewController:dvController4 animated:YES];

    [dvController4 release];

    [detailViewController1 release];
    }
    }

ThirdDetailView

@synthesize theItem1,theTitle,img,body,message,facebook,webview,id1;

     - (id)initWithItem:(NSDictionary *)detaildesc1 Title:(NSString *)title 
    {
if (self = [super initWithNibName:@"ThirdDetailView" bundle:nil]) {
    self.id1=detaildesc1;
    self.theTitle=title;
      urlAddress = [NSString stringWithFormat:@"http://dev-parkguiden.knutpunkten.se/Api/GetPark?parkid=%@",self.id1];
        baseURL =[[NSURL URLWithString:urlAddress]retain];
        jsonData=[NSData dataWithContentsOfURL:baseURL];

        // self.title=title;

        NSDictionary *items=[NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableLeaves error:nil];

         boom=[items objectForKey:@"description"];
         NSLog(@"what is the text:%@",[items objectForKey:@"description"]);

         [self.webview loadHTMLString:boom baseURL:nil];
    }

return self;
    }

enter image description here

FirstView标签栏 enter image description here

2 个答案:

答案 0 :(得分:1)

试试这个

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
 [[NSUserDefaults standardUserDefaults] setValue:[media1 objectAtIndex:indexPath.row] forKey:@"id1"];
    [[NSUserDefaults standardUserDefaults] setValue:[story objectAtIndex:indexPath.row] forKey:@"theTitle"];

     FirstView *dvController4 = [[FirstView alloc] initWithNibName:@"FirstView" bundle:[NSBundle mainBundle]];
    [self.navigationController pushViewController:dvController4 animated:YES];

    [dvController4 release];

    [detailViewController1 release];
    }
    }


 - (void)viewDidLoad {


    [super viewDidLoad];
    id1 =    [[NSUserDefaults standardUserDefaults] valueForKey:@"id1"];
    theTitle = [[NSUserDefaults standardUserDefaults] valueForKey:@"theTitle"];
    NSLog(@"hi %@", id1);
    hello=@"hello";
    NSLog(@"ahhhha sdfgs :%@",theTitle);

    urlAddress = [NSString stringWithFormat:@"http://dev-parkguiden.knutpunkten.se/Api/GetPark?parkid=%@",self.id1];
    baseURL =[[NSURL URLWithString:urlAddress]retain];

    jsonData=[NSData dataWithContentsOfURL:baseURL];

    NSDictionary *items=[NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableLeaves error:nil];

    self.boom=[items objectForKey:@"description"];
    NSLog(@"retard:%@",self.boom);
    NSString *html = [NSString stringWithFormat:@"<html><body><p>%@</p></body></html>", self.boom];  
    [self.webview loadHTMLString:html baseURL:nil]; 


}

我已在我的应用中测试过,在webview中完美展示了您的文字

答案 1 :(得分:0)

嘿我已尝试使用给定网址@"http://dev-parkguiden.knutpunkten.se/Api/GetPark?parkid=56"的代码,并在我的网络视图中显示。 请检查您的IBOulet是否已正确连接


<强>被修改
嘿,你没有在detailViewController1中使用上面代码中的dvController4 ..你刚刚分配了它,然后发布了它但你没有使用过它。这可能是错误。