问题描述
我有这样的结构....
I have a structure like this....
UITableViewController -> UITableViewCell -> UIView
我需要 UIView
才能访问 UITableViewController中的HashTable(
NSMutableDictionary
)
I need the UIView
to access a HashTable (NSMutableDictionary
) in the UITableViewController
是否有一个简单地从ViewCell访问ViewController的方法(使用[ViewCell superview]显然不起作用)....我是否需要使用 [[UIApplication sharedApplication] delegate] ?
Is there a way to access the ViewController simply from the ViewCell (using [ViewCell superview] obviously won't work) ....Do I need to go down through the AppDelegate using [[UIApplication sharedApplication] delegate]
?
谢谢!
推荐答案
我如果我需要,通常会通过创建一个类似的方法来保持从我的UIView到我的UIViewController的弱引用:
I usually maintain a weak reference from my UIView to my UIViewController if I need one, usually by creating a method something like this:
-(MyView*)initWithController:(CardCreatorViewController*) aController andFrame:(CGRect)aFrame
{
if (self = [super initWithFrame:aFrame])
{
controller = aController;
// more initialisation here
}
return self;
}
如果你想要一个更加分离的解决方案,你也可以使用委托模式。我倾向于认为这对于视图及其控制器来说太过分了,但我会将它用于控制器和子控制器系统。
You could also use a delegate pattern if you want a more decoupled solution. I tend to think this is overkill for a view and its controller, but I would use it with a system of controllers and subcontrollers.
这篇关于iphone - 从uitableviewcell访问uitableviewcontroller的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!