最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】参考Your Second iOS App教程,但是点击BirdsMasterViewController中的TableView后,却无法进入详细页面BirdsDetailViewController

iOS crifan 3049浏览 0评论

【问题】

参考:Your Second iOS App – Displaying Information in the Detail Scene,去可以编译运行了出主界面了:

参考教程开发iOS的第二个app:Storyboards – BirdWatching

但是点击Pigeon的TableView:

点击Pigeon无法进入详细信息页面

却无法进入详细信息的页面。

 

【解决过程】

1.确保了prepareForSegue中的isEqualToString后面的值是ShowSightingDetails,而且对应的属性中也的确设置了改值,结果还是不行。

2.去给prepareForSegue加了断点:

给prepareForSegue加了断点

但是调试时,鼠标点击Pigeon后却没有运行到这里。

3.现在只能想办法,去调试,当鼠标(模拟用户)点击Pigeon后,之后事件的处理流程是如何的,然后一点点往下调试了。

想了想,觉得还是此时对于MasterView中,事件点击,还没有正确调用,还没有传递给push的segue呢。

4.再去MasterView中看了看,发现现在是两个Subtitle类型的UITableView,所以去删除掉一个,试试能否解决问题。

结果问题依旧。

5.又试了试Detail view中加了一些断点,但是都是没有运行到.看来还是没有加载到Detail view.

6.找到其他人:

iPhone’s Your Second iOS Application

也遇到了同样问题,无法进入 birds的detail view界面,但是其也没有找到解决办法.

7.参考:

I can’t transition from the Master View Controller to the Detail View Controller

然后去看了看当前的segue,注意到是 Push segue from Master to Birds Detail View Controller:

Push segue from Master to Birds Detail View Controller

如果那人所说的,应该显示类似于"Push Segue from BirdSightingCell to Detail"才对.

很明显,此处是从Master View转换到Detail View,而不是从相关的cell转换到Detail View.

再回去看教程,其中:Design the Detail Scene中的"To create a segue from the master scene to the detail scene . . ."部分,写的是

Control-drag from the table cell in the master scene to the detail scene

而我此处由于不小心,是从Master View中随便按了Control+drag以拖到Detail View,导致生成的segue是“Push segue from Master to Birds Detail View Controller”,所以是错的。

去删掉旧的segue,安装教程的提示,control+drag从table cell 到 detail view:

first select table view cell then ctrl drag

然后再去设置segue的名字为ShowSightingDetails,然后就变成所希望的了segue,“Push segue from BidrsSightingCell to Birds Detail View Controller”:

 

Push segue from BidrsSightingCell to Birds Detail View Controller

然后再去运行,就正常了,点击Pigeon后,可以运行到之前在prepareForSegue处的断点了:

can run breakpoint prepareForSegues

然后就可以进入Detail View了:

can show detail view

 

【总结】

此处点击Table View Cell,之所以没有安装期望进入Detail View的原因是segue设置错了:

之前在新建segue时,不小心错误地,点击的是Master View,然后control+drag拖动到Detail View,对应生成的segue在outline中的名字是“Push segue from Master to Birds Detail View Controller”,

而实际上应该是新建segue时,先选中那个Table View Cell(而非Master View),然后再control+drag拖动到Detail View,即可正常的生成的segue,对应名字是“Push segue from BidrsSightingCell to Birds Detail View Controller”,这样才可以实现,当点击Pigeon那个Table View Cell时,通过segue切换到BirdsDetailViewController。

所以,学到的教训是:在创建segue时,一定要看清楚source和destination!!!不要不小心而搞错对象了。

转载请注明:在路上 » 【已解决】参考Your Second iOS App教程,但是点击BirdsMasterViewController中的TableView后,却无法进入详细页面BirdsDetailViewController

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

网友最新评论 (3)

  1. 额,貌似回错地方了
    fanl198211年前 (2012-12-19)回复
  2. 问题已解决,是我创建AddSightingViewController的.h和.m的文件时,一不小心保存到工程平级的目录上了,很奇怪,xcode里面看到的这两个文件仍然和其他viewcontroller在同一级,把代码移进来就ok了,光顾着在xcode中找原因了,打开磁盘上的文件目录才发现问题,btw,多谢你的回复. ps:我的邮箱收到的你的回复,是[email protected],并提示请勿回复
    fanl198211年前 (2012-12-19)回复
    • 你之前用gmail邮箱发给我邮件的:“关于second iOS app的一个问题,急” 然后我用我的邮箱 admin at crifan dot com 回复你的。你没收到???
      crifan11年前 (2012-12-19)回复
95 queries in 0.180 seconds, using 22.21MB memory