小编Mic*_*ren的帖子

在prepareForSegue完成之前调用的viewDidLoad

我认为viewDidLoad会在prepareForSegue结束后被调用.这就是Hegarty如何教他的斯坦福大学课程(最近在2013年2月).

但是,今天我第一次注意到,在READForSegue完成之前调用了viewDidLoad.因此,我在prepareForSegue中设置的属性不可用于目标viewDidLoad方法中的destinationViewController.

这似乎与预期的行为相反.

UPDATE

我只知道发生了什么事.在我的destinationViewController中,我有一个自定义setter,每次更新"model"时都会重新加载tableView:

DestinationViewController    
- (void)setManagedObjectsArray:(NSArray *)managedObjectsArray
    {
        _managedObjectsArray = [managedObjectsArray copy];
        [self.tableView reloadData];
    }
Run Code Online (Sandbox Code Playgroud)

事实证明,因为destinationViewController是UITableViewController的子类...调用'self.tableView'会强制加载视图.根据Apple的文档,调用视图控制器的view属性可以强制加载视图.UITableViewController的视图是tableView.

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html

因此,在prepareForSegue中,以下行强制加载destinationViewController的视图:

vc.managedObjectsArray = <custom method that returns an array>;
Run Code Online (Sandbox Code Playgroud)

为了解决这个问题,我将destinationViewController模型的自定义setter更改为:

- (void)setManagedObjectsArray:(NSArray *)managedObjectsArray
    {
        _managedObjectsArray = [managedObjectsArray copy];
        if ([self isViewLoaded]) {
            [self.tableView reloadData];
        }
    }
Run Code Online (Sandbox Code Playgroud)

如果tableView在屏幕上,这将只重新加载tableView.因此,在prepareForSegue期间不强制加载视图.

如果有人反对这个过程,请分享您的想法.否则,我希望这可以防止一个人长时间不眠之夜.

storyboard viewdidload ios segue

28
推荐指数
2
解决办法
1万
查看次数

Heroku 偶尔返回找不到“主机名”

我正在创建一个在 Heroku 上使用 Rails API 后端的 iOS 应用程序。定期(每 20 个 API 调用一次),找不到 heroku。返回以下 NSError:

Error Domain=NSURLErrorDomain Code=-1003 "A server with the specified hostname could not be found." UserInfo=0x755ce00 {NSErrorFailingURLStringKey=https://xxx.herokuapp.com/api/v1/matchups, NSErrorFailingURLKey=https://xxx.herokuapp.com/api/v1/matchups, NSLocalizedDescription=A server with the specified hostname could not be found., NSUnderlyingError=0x71ca730 "A server with the specified hostname could not be found."
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails heroku nserror ios

5
推荐指数
1
解决办法
867
查看次数

标签 统计

ios ×2

heroku ×1

nserror ×1

ruby-on-rails ×1

segue ×1

storyboard ×1

viewdidload ×1