Apple 代码示例:TouchCells,它是如何工作的?
我一直在研究自定义 UITableViewCells 并遇到了来自苹果的 TouchCells 示例: TouchCells 示例项目
我无法弄清楚应用程序如何负载。如果您查看 AppDelegate.m
,您会看到以下内容:
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
// create window and set up table view controller
detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
detailViewController.loadView;
[window addSubview:navController.view];
[window makeKeyAndVisible];
}
它似乎会加载 DetailViewController
。
但是,当应用加载时,会加载一个 MyTableViewController
类型的 UITableViewController
,并加载标题 TouchCells
。我查看了 MainWindow.xib
并且没有 MyTableViewController
(据我所知)。
当我在 MyTableViewController.m
中放置断点时
- (void)viewDidLoad
{
// load our data from a plist file inside our app bundle
NSString *path = [[NSBundle mainBundle] pathForResource:@"tableData" ofType:@"plist"];
self.dataArray = [NSMutableArray arrayWithContentsOfFile:path];
}
,该断点会在 AppDelegate.m
的 applicationDidFinishLaunching
中的断点之前被命中。我想这意味着 MyTableViewController
首先被加载,但我无法弄清楚该调用在代码中的位置。
有人可以帮我弄清楚 TouchCells
示例的逻辑流程吗?
谢谢
答案
所选答案包含正确的信息,但 @Caleb 提供的答案显示了如何获取该信息。
谢谢大家
I've been working on custom UITableViewCells and came across the TouchCells example from apple: TouchCells Example Project
I can't figure out how the application loads. If you look at AppDelegate.m
, you see this:
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
// create window and set up table view controller
detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
detailViewController.loadView;
[window addSubview:navController.view];
[window makeKeyAndVisible];
}
which would seem to load a DetailViewController
.
However, when the app loads, there is a UITableViewController
of type MyTableViewController
loaded with the Title TouchCells
. I looked at MainWindow.xib
and there is no MyTableViewController
(as far as I can tell).
When I put break points in
- (void)viewDidLoad
{
// load our data from a plist file inside our app bundle
NSString *path = [[NSBundle mainBundle] pathForResource:@"tableData" ofType:@"plist"];
self.dataArray = [NSMutableArray arrayWithContentsOfFile:path];
}
of MyTableViewController.m
, the breakpoint is hit before a breakpoint in applicationDidFinishLaunching
from AppDelegate.m
. I guess this means the MyTableViewController
is being loaded first, but I can't for the life of me figure out where that call is in the code.
Can anybody help me figure out the logical flow of the TouchCells
example?
Thanks
Answer
The selected answer has the correct information in it, but the answer @Caleb provided shows how to get that information.
Thanks everyone
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当调用 applicationDidFinishLaunching 时,接口构建器连接将已经设置。因此,任何需要初始化的类都将在 applicationDidFinishLaunching 之前调用。如果您想知道调用了哪些方法,请在 XCode 4 中的调试导航器内部命中断点后跟踪堆栈跟踪。
更新:
在 MainWindow.xib 内部展开导航控制器,然后您将看到会找到MyTableViewController。
When applicationDidFinishLaunching is called the interface builder connections will be set already. Therefore any class that needs to be initialized will be called before applicationDidFinishLaunching. If you are wondering as to what methods are calling it follow the stack trace once your break point is hit inside of the Debug Navigator in XCode 4.
Update:
Inside of MainWindow.xib expand the Navigation Controller and you will find MyTableViewController.
假设您使用的是 Xcode 4,您可以单击 IB 停靠区域底部的小扩展按钮:
这将让您看到导航控制器中包含的对象,如下所示:
现在您可以看到 MyTableViewController当加载主笔尖时,将创建作为导航控制器的根控制器。另一种方法是使用“编辑器”->“在文档结构中显示”命令。
Assuming you're using Xcode 4, you can click the little expansion button at the bottom of the IB dock area:
That'll let you see the objects contained in the navigation controller, like this:
Now you can see that a MyTableViewController is created as the navigation controller's root controller when the main nib is loaded. Another way to do this is to use the Editor->Reveal in Document Structure command.