【发布时间】:2011-05-06 11:11:34
【问题描述】:
在 IB 中,我在 UIScrollView 中创建了 UIView。两者的文件所有者都是名为 JLViewController 的 UIViewController。 UIView 连接到 BodyClock 类。
BodyClock 类在视图内绘制图形。它还创建了几个充当触摸热点的小视图。当一个热点被触摸时,它会显示一个信息警报,并带有一个按钮以获取更多详细信息。我需要告诉 JLViewController 显示详细信息。我想我可以通过让 ViewController 成为 HotSpot 的代表来做到这一点。作为我在 BodyClock 类中创建热点的方式,我无法弄清楚如何将热点委托设置为 JLViewController。我正在尝试做这样的事情..
//Code in BodyClock
//create the hot spot
id viewController = [self nextResponder];
HelpHotSpot *helpHotSpot = [[HelpHotSpot alloc] initWithFrame:CGRectMake(start_x, melatoninHeightEnd_y, 80, 40)];
helpHotSpot.delegate = viewController;
[viewController addSubview:helpHotSpot];
[helpHotSpot release];
//Code in the HotSpot after touch and request for more info
//notify JLViewController to display the details
if ([self.delegate respondsToSelector:@selector(hotSpotMore:)]) {
[self.delegate hotSpotMore:itemDetails];
}
除了 respondsToSelector 失败之外,一切正常。如果我 NSLog viewController 或 self.delegate 我得到...
UIScrollView: 0x7443c20;框架等...
我期待 JLViewController: 而不是 UIScrollView: 所以我认为这是问题所在。
如何将代理设置为这些子视图的 ViewController?
有可能吗,还是我应该改用通知?
【问题讨论】:
-
我仍然对如何执行此操作感兴趣,但已经通过使用 NSNotificationCenter 解决了我的问题。非常容易实现并且效果很好。
标签: iphone xcode delegates uiviewcontroller subview