Objective - C 自定义表视图问题

发布于 2024-11-09 17:35:21 字数 877 浏览 0 评论 0原文

我有这样的代码:

 - (void)viewDidLoad {
    [super viewDidLoad];
    NSLog(@"ViewDidLoad");

    username = @"itemstiubhart1";
    titleEle = @"titlestiubhart1";
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    NSLog(@"ViewWillAppear");
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    if ([stories count] == 0) {
        NSString * path = @"http://myurl.com/events.php";
        [self parseXMLFileAtURL:path];
    }
    NSLog(@"viewDidAppear");
}

- (void)viewWillDisappear:(BOOL)animated {
}

- (void)viewDidDisappear:(BOOL)animated {
}

您可能需要比这更多的代码,但是我确信我错过了一些相当基本的东西。基本上我的问题是这样的,viewDidLoad方法执行得很好,但是下一个应该运行的方法(viewWillAppear)根本不运行......并且出现一个空白的表视图。我错过了一些基本的东西吗?或者我的问题可能更复杂一些?只是看起来有点奇怪。我在另一个项目中有相同的代码,但该项目使用导航控制器,而这个项目使用视图控制器,我认为这与此有关,因为另一个项目工作正常。

谢谢,

杰克

I have this code:

 - (void)viewDidLoad {
    [super viewDidLoad];
    NSLog(@"ViewDidLoad");

    username = @"itemstiubhart1";
    titleEle = @"titlestiubhart1";
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    NSLog(@"ViewWillAppear");
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    if ([stories count] == 0) {
        NSString * path = @"http://myurl.com/events.php";
        [self parseXMLFileAtURL:path];
    }
    NSLog(@"viewDidAppear");
}

- (void)viewWillDisappear:(BOOL)animated {
}

- (void)viewDidDisappear:(BOOL)animated {
}

You may need more of my code than this, however I'm sure I'm missing something fairly fundamental. Basically my problem is this, the viewDidLoad method executes fine, however the next method that should run (viewWillAppear) simply doesn't run at all...And a blank table view appears. Am I missing something fundamental? Or is my problem likely a bit more complex? Just seems a bit strange. I have the same code in another project, but that project uses a navigation controller and this one uses a view controller, I think it has something to do with that as the other project works fine.

Thanks,

Jack

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

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

发布评论

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

评论(2

蓝海似她心 2024-11-16 17:35:21

我猜您是通过 [view addSubview:subview] 手动将视图添加为子视图。

在这种情况下,您必须自己调用 -viewWillAppear:

另请检查此问题Apple Docs (自定义视图控制器必须实现 viewWillAppear)。

I guess that you are adding the view manually as a subview through [view addSubview:subview].

In this case, you have to call -viewWillAppear: yourself.

Check also this question and Apple Docs (a custom view controller has to implement viewWillAppear).

踏雪无痕 2024-11-16 17:35:21

解析完成后,您必须再次重新加载表。由于数据值为空,表视图可能会变为空白

You have to reload table again when parsing is complete. Table view may coming blank because of empty data values

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