PushViewController 或 PresentModalViewController 在同一屏幕中呈现某些内容

发布于 2025-01-03 02:14:07 字数 2908 浏览 0 评论 0原文

我有一个 iPad 应用程序,可以从 RSS 提要中提取信息,但我不想在下一个屏幕中推送信息,而是希望仍将其显示在同一屏幕中(参见图片)

当我使用 pushViewController 时什么也没发生。当我使用 presentModalViewController 时,蓝色背景会更改为网络视图。但我想要的是,当我单击左侧提要中的一行时,右侧的网络视图会获取网站。

我通过使用 webview 推送到新屏幕来测试这一点,这确实有效,但我希望所有这些都在同一个屏幕上

这是代码(显然我已经尝试了一些不同的东西,只是将其注释掉了) :

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {    
    //EDITED to go to a webView instead of another table of info
    if (_webViewController == nil) {
        self.webViewController = [[[WebViewController alloc] 
                                    initWithNibName:@"WebViewController" bundle:[NSBundle mainBundle]] autorelease];
    }

    MWFeedItem *entry = [parsedItems objectAtIndex:indexPath.row];
    _webViewController.entry = entry;
    //[self.navigationController  pushViewController:_webViewController animated:YES];
    [self presentModalViewController:_webViewController animated:YES];

    //BELOW UNFINISHED SO EDITED OUT
    //self.webViewController._entry=[objectAtIndexPath:indexPath.row];

    // Deselect
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];

}

不确定我的 ViewController 信息是否必要,但这是一个删节版本(位置不同,但其他一切都相同)

- (void)viewDidLoad
{
    [super viewDidLoad];

    [scroll setScrollEnabled:YES];
    [scroll setContentSize:CGSizeMake(3840, self.view.frame.size.height)];

    ScheduleRVC *_scheduleRVC = [[ScheduleRVC alloc] initWithNibName:@"ScheduleRVC" bundle:nil];
    [_scheduleRVC.view setFrame:CGRectMake(408, 283, 340, 572)];
    [scroll addSubview:_scheduleRVC.view];

    MySchedule *_mySchedule = [[MySchedule alloc] initWithNibName:@"MySchedule" bundle:nil];
    [_mySchedule.view setFrame:CGRectMake(10, 57, 340, 800)];
    [scroll addSubview:_mySchedule.view];   

    WebViewController *_webViewController = [[WebViewController alloc] initWithNibName:@"WebViewController" bundle:nil];
    [_webViewController.view setFrame:CGRectMake(408, 57, 340, 184)];
    [scroll addSubview:_webViewController.view];

}

输入图片描述这里

请帮忙(这会拯救一只小猫)

--ADDITION 如果有帮助的话,这里是从 RSS 推送到 WebView 的代码(但就像我说的,我希望它们一起出现在屏幕上,而 SplitView 不适用于我正在做的事情)

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    // Show detail
    if (_webViewController == nil) {
        self.webViewController = [[[WebViewController alloc] initWithNibName:@"WebViewController" bundle:[NSBundle mainBundle]] autorelease];
    }

    MWFeedItem *entry = [parsedItems objectAtIndex:indexPath.row];
    _webViewController.entry = entry;
    [self.navigationController pushViewController:_webViewController animated:YES];


    // Deselect
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];

}

I have an iPad app that pulls info from an RSS feed, but instead of pushing to present information in the next screen, I want to still show it in the same screen (see image)

When I use pushViewController NOTHING happens. When I use presentModalViewController the blue background changes to the webview. But what I want is when I click on a row from the feed on the left, the webview on the right gets the website.

I tested this with pushing to a new screen with a webview, and this DOES work, but I want it all in the same screen

Here is the code (obviously I've tried a few different things, and just left it in commented out):

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {    
    //EDITED to go to a webView instead of another table of info
    if (_webViewController == nil) {
        self.webViewController = [[[WebViewController alloc] 
                                    initWithNibName:@"WebViewController" bundle:[NSBundle mainBundle]] autorelease];
    }

    MWFeedItem *entry = [parsedItems objectAtIndex:indexPath.row];
    _webViewController.entry = entry;
    //[self.navigationController  pushViewController:_webViewController animated:YES];
    [self presentModalViewController:_webViewController animated:YES];

    //BELOW UNFINISHED SO EDITED OUT
    //self.webViewController._entry=[objectAtIndexPath:indexPath.row];

    // Deselect
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];

}

Not sure if my ViewController info is necessary, but here is an abridged version (placements are different, but everything else is the same)

- (void)viewDidLoad
{
    [super viewDidLoad];

    [scroll setScrollEnabled:YES];
    [scroll setContentSize:CGSizeMake(3840, self.view.frame.size.height)];

    ScheduleRVC *_scheduleRVC = [[ScheduleRVC alloc] initWithNibName:@"ScheduleRVC" bundle:nil];
    [_scheduleRVC.view setFrame:CGRectMake(408, 283, 340, 572)];
    [scroll addSubview:_scheduleRVC.view];

    MySchedule *_mySchedule = [[MySchedule alloc] initWithNibName:@"MySchedule" bundle:nil];
    [_mySchedule.view setFrame:CGRectMake(10, 57, 340, 800)];
    [scroll addSubview:_mySchedule.view];   

    WebViewController *_webViewController = [[WebViewController alloc] initWithNibName:@"WebViewController" bundle:nil];
    [_webViewController.view setFrame:CGRectMake(408, 57, 340, 184)];
    [scroll addSubview:_webViewController.view];

}

enter image description here

Please help (it will save a kitten)

--ADDITION
If it helps any, here's the code that works pushing from the RSS to a WebView (but like I said, I want them to appear on the screen together, and SplitView won't work for what I'm doing)

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    // Show detail
    if (_webViewController == nil) {
        self.webViewController = [[[WebViewController alloc] initWithNibName:@"WebViewController" bundle:[NSBundle mainBundle]] autorelease];
    }

    MWFeedItem *entry = [parsedItems objectAtIndex:indexPath.row];
    _webViewController.entry = entry;
    [self.navigationController pushViewController:_webViewController animated:YES];


    // Deselect
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];

}

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

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

发布评论

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

评论(1

櫻之舞 2025-01-10 02:14:07

好吧,如果您想要一个非常简单的解决方案,您可以通过简单地不动画转换到模态控制器视图来假装保持在同一视图中,即。 [selfpresentModalViewController:_webViewControlleranimated:NO];。当您关闭 UIWebView 时,您还必须禁用动画,即。 [自我解雇ModalViewControllerAnimated:NO]

或者,您可以将 RSS Feed 视图和 UIWebView 放在同一个视图中,当您想要显示 Web 视图时,只需隐藏 RSS Feed 视图(并取消隐藏 UIWebView),并在需要 RSS Feed 时执行相反的操作可见的。

希望有帮助(足以拯救那只小猫)。

编辑:我应该提到,这些不一定遵循苹果推荐的设计模式,我只是提供解决您当前问题的解决方案。我需要更多信息来确定您的设计是否正确。

Well if you want a dead-simple solution, you can fake staying in the same view by simply not animating the transition to your modal controller view, ie. [self presentModalViewController:_webViewController animated:NO];. You'd also have to disable animation when you dismiss the UIWebView, ie. [self dismissModalViewControllerAnimated:NO].

Alternatively, you could have both your RSS Feed view and the UIWebView in the same view, and simply hide the RSS Feed view (and unhide the UIWebView) when you want to present the web view, and do the opposite when you want the RSS Feed visible.

Hope that helps (enough to save that kitten).

EDIT: I should mention that these are not necessarily following Apple's recommended design patterns, I'm just providing solutions that will solve your current problem. I'd need more information to determine whether your design is correct or not.

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