自定义UIView作为UITableView委托和数据源? [英] Custom UIView as UITableView delegate and datasource?

查看:391
本文介绍了自定义UIView作为UITableView委托和数据源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一个相当复杂的iPad应用程序 - 我的第一个更大的应用程序。

I am writing a fairly complex iPad app - my first bigger one.

这个应用程序有一些自定义的UIViews提出相当复杂的数据,这些视图不占用整个屏幕,并且在任何时候都可以(并且很可能)会在屏幕上显示很多视图(虽然只有一个视图处于显示表格的展开状态)。

This app has some custom UIViews that present fairly complex data, including a table. These views do not take up the whole screen, and there can (and likely will) be many of them on screen at any time (though only one would be in an "expanded" state where the table is shown).

这是一个基本的例子,应该传达基本原则:

Here's a basic example that should convey the basic principle:

请注意,这些东西不应该在popovers中;相反,FamilyViews展开以显示其详细数据。 (还请注意,这个模型只是为了这个问题而创建,并且与我的界面如何看起来没有什么关系;我知道这是不好的屏幕设计)

Please note that these things are not supposed to be in popovers; instead, the FamilyViews expand to show their detailed data. (And please also note that this mockup was only created for the sake of this question and has little to do with how my interface is going to look; I know this is not good screen design)

我不确定将这些自定义视图的委托和数据源放在哪里:


  • 为当前屏幕委托和数据源设置 ViewController 是不明智的,因为它不仅仅是VC主视图的一部分。

  • strong> View 本身代理和数据源似乎有点奇怪,因为它感觉像给予视图太活跃的角色;

  • 使底层的模型对象数据源看起来太紧耦合,也打破了MVC。

  • Making the ViewController for the current screen delegate and datasource is unelegant, because it's not just one table that's part of the VC's main view.
  • Making the View itself the delegate and datasource seems a bit weird to me because it feels like giving the view too active a role; making it into a half-controller.
  • Making the underlying model object the datasource seems too tightly coupled, and also breaks MVC. And it doesn't answer the question of who should be the delegate.

我打算让每一个FamilyViews委托和datasource为自己的表。对这些表的操作必须耦合到FamilyView的委托(ViewController),但这不应该是一个问题,应该吗?

I'm tending towards making each of these "FamilyViews" delegate and datasource for their own tables. Action on these tables will have to be coupled to the FamilyView's delegate (the ViewController), but that shouldn't be a problem, should it?

一些输入?

推荐答案

视图应该知道如何绘制自己和布局他们的子视图,

Views should know how to paint themselves and layout their sub views, depending on their properties, and that's it.

你肯定应该让一个控制器类作为代理而不是视图本身。

You definitely should let a controller class be the delegate instead of the view itself.

代理控制器不一定是显示视图的视图控制器。它可以很容易地是一个完全独立的控制器类,只知道如何处理视图需要什么。

The delegate controller doesn't have to be the view controller that displays the view, though. It could easily be a completely separate controller class that only knows how to handle what the view requires.

这篇关于自定义UIView作为UITableView委托和数据源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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