• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - UITableView prepareForSegue 不推送到 UIWebView

[复制链接]
菜鸟教程小白 发表于 2022-12-12 10:48:26 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我正在尝试从 WebListViewController 推送到 WebPageViewController,因此当按下单元格时,它将推送到 UIWebView 以显示与之相关的网络文章。但我就是不能让它工作-

WebListViewController.m

#import "WebListViewController.h"
#import "Feed.h"

@interface WebListViewController ()
@property (strong, nonatomic) NSArray *headlinesArray;
@end

@implementation WebListViewController
@synthesize tableView = _tableView;
@synthesize headlinesArray;

- (UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath
{

    static NSString *CellIdentifier = @"standardCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    Feed *feedLocal = [headlinesArray objectAtIndex:indexPath.row];
    NSString *headlineText = [NSString stringWithFormat"%@", feedLocal.headline];
    cell.textLabel.text = headlineText;

    return cell;
}


- (void)prepareForSegueUIStoryboardSegue *)segue senderid)sender
{
    if ([segue.identifier isEqualToString"webpage"]) {
    UITableViewCell *cell = (UITableViewCell*)sender;
    NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];

    WebPageViewController *wpvc = (WebPageViewController *) [segue destinationViewController];
    wpvc.buttonNumber = _buttonNumber;
    Feed *feedLocal = [headlinesArray objectAtIndex:indexPath.row];
    NSString *stringWeb = [NSString stringWithFormat"%@", feedLocal.links.web.href];
    wpvc.stringWeb = stringWeb;
}

}

WebPageViewController.h

@interface WebPageViewController : UIViewController <UIWebViewDelegate>
@property (nonatomic) int buttonNumber;
@property (strong, nonatomic) IBOutlet UIWebView *webView;
@property (strong, nonatomic) NSString *stringWeb;
@end

WebPageViewController.m

#import "WebPageViewController.h"
#import "Feed.h"

@interface WebPageViewController ()
@property (strong, nonatomic) NSArray *headlinesArray;
@end
@implementation WebPageViewController
@synthesize stringWeb;
@synthesize headlinesArray;

-(void)viewWillAppearBOOL)animated {
    NSURL *url = [NSURL URLWithString:stringWeb];
    [self.webView loadRequest:[NSURLRequest requestWithURL:url]];
}

-(void)viewWillDisappearBOOL)animated {
    [self.webView stopLoading];
}

JSON 响应

{
    "timestamp": "2013-05-04T16:38:48Z",
    "feed": [{
        "headline": "Text of headline",
        "links": {
            "web": {
                "href": "http://website.com/article"
            },

我今天刚刚添加了 部分,因为我认为这可能是正在发生的事情,但它仍然无法正常工作。我知道 cellForRowAtIndexPath 是正确的,因为我在控制台中看到了它的所有正确数据。当我运行程序时,它似乎从未到达 WebPageViewController,所选单元格保持突出显示。我无法弄清楚问题是什么,如果它的 prepareForSegue 或需要添加 didSelectRowAtIndexPath 或其他不同的东西。

(我从 API 中提取 JSON 数据。)

任何建议都会非常有帮助,我会添加任何需要的代码,谢谢!



Best Answer-推荐答案


我猜 standardCell 是您在 Storyboard 中定义为原型(prototype)单元的单元?如果是这样,请确保您右键单击该单元格并将“选择”属性拖动到您希望单元格推送到导航 Controller 上的 View Controller 。

How to create a segue connection to another view controller

另外,确保第一个 View 嵌入在导航 Controller 中。如果不是,请在 Storyboard 中选择它,然后转到 Editor-menu,选择“Embed In”,然后选择“Navigation Controller”。

How to embed a view in a navigation controller

关于ios - UITableView prepareForSegue 不推送到 UIWebView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16379453/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap