Objective - C 自定义表视图问题
我有这样的代码:
- (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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我猜您是通过
[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
).解析完成后,您必须再次重新加载表。由于数据值为空,表视图可能会变为空白
You have to reload table again when parsing is complete. Table view may coming blank because of empty data values