如何使用情节提要对 UITabbarcontroller 进行子类化? [英] How do I subclass a UITabbarcontroller using storyboards?

查看:30
本文介绍了如何使用情节提要对 UITabbarcontroller 进行子类化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用故事板的标签栏应用程序.Tab 1 是一个带有 Mapview & 的 UIViewControllerTab 2 是一个 UITableViewController.

I have a tabbar application using storyboards. Tab 1 is a UIViewController with Mapview & Tab 2 is a UITableViewController.

appdelegate 调用网络获取(通过自定义类)并获取该网络响应并解析它(通过自定义类),然后将信息放入 CD-db(通过自定义类).

The appdelegate calls for a web fetch (via a custom class) and takes that web response and pareses it (via a custom class) and then puts the info in a CD-db (via a custom class).

MapVC 从 CD-db 获取结果并填充要循环的 NSMutableArray(属性).该数组包含一个带有 2 个坐标的自定义 CD-db 对象,用于在 for 循环中创建 MKAnnotation.计算从每个 MKAnnotation 到 userLocation 的距离,并且 MyLocation Class 对象在其字幕属性中使用距离值完成.因此,地图上的每个图钉都显示一个标题(名称)&副标题(距离).

MapVC fetches results from the CD-db and populates an NSMutableArray (property) to be looped thru. The array contains a custom CD-db object with 2 coordinates which are used to create an MKAnnotation in the for loop. The distance from each MKAnnotation to userLocation is calculated and the MyLocation Class object is completed with a distance value in its subtitle property. Thus each pin on the map displays a title (name) & subtitle (distance).

TableVC 创建对 CD-db 的单独提取并填充其数组属性以在 cellForRowAtIndexPath (CFRAIP) 中使用.

TableVC creates a separate fetch to the CD-db and populates its array property to be used in the cellForRowAtIndexPath (CFRAIP).

现在我希望 tableview 也显示每个单元格中的距离.所以有人建议我将 uitabbarcontroller 子类化,并将 TableVC.tableview 的委托/数据源设置为 MapVC.我的问题是,如何子类化 uitabbarcontroller 并设置委托和数据源?

Now I want the tableview to also display the distance in each cell. So it has been suggested I subclass the uitabbarcontroller and set the delegate/datasource of the TableVC.tableview to the MapVC. My question is, how do I subclass my uitabbarcontroller and set the delegate and datasource?

类似于:在应用程序委托中获取窗口的 rootviewcontroller?

Something like: in app delegate get the window's rootviewcontroller?

推荐答案

首先你需要继承 UITabBarController.在Xcode中新建一个文件,设置UITabBarController为父类.

First you need to subclass UITabBarController. Make a new file in Xcode, set UITabBarController as the parent class.

然后转到您的故事板并选择 tabbarcontroller,将其自定义类设置为您刚刚创建的类.

Then go to your storyboard and select the tabbarcontroller, set its custom class to the class you just make.

在 tabVC 的 viewDidLoad 中获取其子 VC 并找到您想要的.这是伪代码,我可以稍后整理:

In viewDidLoad of the tabVC get its sub VC's and find the ones you want. Here's the pseudo code, I can tidy it up later:

CSMapListViewController *mapListViewController;
CSTableViewController *tableViewController;

for (UIViewController *vc in self.viewControllers)
{
    if ([vc isKindOfClass:[CSMapListViewController class]])
    {
        mapListViewController = (CSMapListViewController *)vc;
    } else if ([vc isKindOfClass:[CSTableViewController class]])
    {
        tableViewController = (CSTableViewController *)vc;
    } 
}

tableViewController.tableview.datasource = mapListViewController;

希望有所帮助.

这篇关于如何使用情节提要对 UITabbarcontroller 进行子类化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆