问题标签 [viewdidload]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
1658 浏览

iphone - does this code really need a "[self.tableView reloadData]" at the end of viewDidLoad (in a UITableViewController)

The SimpleEKDemo sample has a "[self.tableView reloadData]" at the end of viewDidLoad in the RootViewController.m file.

Is this necessary? Any ideas why this line was put in? Wouldn't the view get drawn subsequently after the viewDidLoad via it's calls to the delegate to methods like "cellForRowAtIndexPath"?

EDIT - I did note this in the doco (see below) - it's still not clear to me how the above line of code is required - isn't it the case that if you went to another view, and then back to this view, THEN if (a) the view is re-initialised than it would have to populate itself again anyway, or (b) if the view wan't re-initialised the "viewDidLoad" method wouldn't be called hence you wouldn't be putting the "reloadData" line of code at the end of the viewDidLoad method in either case no?

UITableView overrides the layoutSubviews method of UIView so that it calls reloadData only when you create a new instance of UITableView or when you assign a new data source. Reloading the table view clears current state, including the current selection. However, if you explicitly call reloadData, it clears this state and any subsequent direct or indirect call to layoutSubviews does not trigger a reload.

0 投票
1 回答
171 浏览

iphone - 关于 IBOutlets 的令人困惑的错误

我很长时间以来一直在努力解决这个问题,但我就是无法弄清楚。

在我的视图控制器的视图 Did Load 方法中,如果我尝试对通过 IBOutlet 连接的 imageView 进行一些更改,它是无响应的。它根本不响应即时对 IBOutlet 元素所做的任何更改。例如:如果我在 IB 中有一个 imageView 并且它通过 IBOutlet 连接,并且我尝试设置此 ImageView 的隐藏属性,它不会响应。为什么会这样,我无法理解。

然后我将该 imageView 添加到另一个视图,并将组合作为子视图添加到该视图。然后我可以更改这个 imageView 元素。但是如果我尝试用 viewDidLoad 以外的其他方法访问这个 imageView,应用程序就会崩溃。imageView 是一个实例变量。

0 投票
7 回答
29280 浏览

iphone - viewDidLoad(), LoadView()

viewDidLoad()LoadView()有什么区别?它们在哪些方面彼此不同?

当我们不使用 XIB 开发应用程序时,哪一个更好?

谢谢 。

0 投票
2 回答
820 浏览

iphone - iPhone 查看方法

请逐步告诉我iOS的不同视图方法。请解释先执行哪个方法等。我的意思是说什么时候执行哪个方法?

0 投票
2 回答
814 浏览

ios4 - viewDidLoad 在构造函数之前调用

这个问题与这个有关。我有两个构造函数:

在另一个对象中,我有两个名为 *bannerPreview 和 *bannerVideo 的类实例,用 initWithPreview 和 initWithVideo 进行了初始化。这里发生了什么:在预览构造函数中,我无法访问 IBOutlets,因为它们是 nil,而它们不在横幅中。但是bannerVideo的方法viewDidLoad在构造函数完成之前被调用,而bannerPreview的viewDidLoad没有。我在类中添加了一个字符串测试,并在上面列出的两种方法中添加了一个 NSLog(@"Foo") ,我的输出是:

我应该如何处理这种行为?

0 投票
2 回答
441 浏览

iphone - 为什么“numberOrRowsInSection”在“viewDidLoad”中途被调用?

背景:

  1. 在我的 viewDidLoad 中,我正在将测试日历数据(通过 EventKit)加载到 iPhone。我注意到,当表格视图第一次加载时,它看不到这些数据。

  2. 当我查看日志消息的序列时,我发现它是这样的:

在这里记录:

问题)

  • 为什么“numberOrRowsInSection”在“viewDidLoad”中途被调用?我问这个,因为这就是我所看到的(这是应该发生的事情吗?)。

  • 如果这是正常的,您不能确定 viewDidLoad 将在 numberOrRowsInSection 之前完成,那么这意味着您需要在“viewDidLoad”方法的末尾使用“[self.tableView reloadData]”来确保它确实更新?

0 投票
2 回答
566 浏览

iphone - 在 viewDidLoad 之后加载图像

我有一个视图,可以在 viewDidLoad 期间将 100 多个图像加载到屏幕上,如下所示:

这需要一些时间来加载(5 秒以上),我记得知道你应该只在屏幕上加载你需要的东西,所以我更喜欢加载前 10 个图像,允许视图加载,然后添加其他功能中的剩余图像,因为它们最初在屏幕外,直到用户向下滚动。最好的地方在哪里?我是否只是在 viewDidLoad 中调用另一个函数,例如 [self loadTheRest]; 或 [self performSelector:@selector(loadTheRest) withObject:nil afterDelay:0.3f]; ?

在此先感谢您的帮助!

0 投票
3 回答
2041 浏览

iphone - 在 viewDidLoad 之后加载数据

我有一个 viewController 需要我加载一系列图像并将它们显示在屏幕上,但是在 viewDidLoad 中加载这些图像需要一段时间,并且在视图出现在屏幕上之前会有延迟。

有没有一种方法可以在 viewDidLoad 中仅加载屏幕上可见的前 5 个图像,然后在 viewController 加载后立即加载剩余的图像?

这是 viewWillAppear 或 viewDidAppear 的用途吗?是否有其他地方最适合在不延迟用户响应时间的情况下加载内容?

提前非常感谢!

0 投票
2 回答
1503 浏览

ios4 - 如何关闭 viewDidLoad 上的模态视图

我正在为 Twitter XAuth 登录创建一个库,并且我已经让一切工作得很好。除非我使用计时器在 0.5 秒内将其关闭,否则应用程序不会关闭 viewDidLoad 方法上的模式视图。有没有办法从 viewDidLoad 中消除模式视图?

0 投票
1 回答
409 浏览

iphone - 在 viewDidLoad 中启动人员选择器?

我想在我的应用程序完成加载后立即启动联系人列表人员选择器,但显而易见的事情似乎不起作用。

名为“name”的 UILabel 已正确设置,但人员选择器未显示。我连接了一个按钮,可以在按下人员选择器时实例化它,而且效果很好。

有什么建议么?

谢谢!