从表视图推送到包含选项卡栏的视图时,无法在 Web 视图中分配数据

发布于 2025-01-04 09:16:01 字数 2081 浏览 2 评论 0原文

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

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

当我的 ThirdDetailView 是四个选项卡栏中的视图之一时,就会出现问题。我已将这四个选项卡栏放置在名为firstView 的视图中,以便单击表视图导航到包含四个选项卡栏的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;
    }

在此处输入图像描述

FirstView 标签栏 在此处输入图像描述

I'm parsing a json object and populating it in table view.

When the table view row is selected it navigates to a detailed view controller named as "ThirdDetailView" and was able to assign the parsed data in my ThirdDetailView (using web view).

Problem arises when my ThirdDetailView is one of the view in my four tab bars .I have placed those four tabbar in a view called firstView, So that clicking on the tableview navigates to firstView containing four tabbars showing the ThirdDetailView as highlighted as the first tab.if this is the case data is not getting loaded in the web view.

below is the code:

- (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 Tabbar
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

童话 2025-01-11 09:16:01

试试这个,

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


}

我在我的应用程序中测试过,可以在网络视图中完美显示您的文本

Try Out this

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


}

I have tested in my app in perfectly show your text in webview

只有一腔孤勇 2025-01-11 09:16:01

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


已编辑
嘿,在上面的代码中,您没有在 dvController4 中使用 detailViewController1 。您刚刚分配了它,然后释放了它,但您还没有使用它。这可能是漏洞。

Hey I have tried your code with the given URL
@"http://dev-parkguiden.knutpunkten.se/Api/GetPark?parkid=56"
and it's showing in my web view.
Please check that your IBOulet is connected properly


Edited
hey you haven't used detailViewController1 in dvController4 in the above code..You have just allocated it and then released it but you haven't used it.This might be the bug.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文