0
在我的HypnosisViewController.m
我有这个代码添加UIView
子类,HypnosisView
到窗口。我的目标是在UISegmented
控件更改其值时设置HypnosisView
实例的属性UIColor circleColor
。如何从UIViewController调用UIView子类方法?
- (void) loadView
{
CGRect frame = [[UIScreen mainScreen] bounds];
HypnosisView *v = [[HypnosisView alloc] initWithFrame:frame];
CGRect segment = CGRectMake(200, 300, 75, 20);
UISegmentedControl *colors = [[UISegmentedControl alloc]initWithFrame:segment];
[v addSubview:colors];
[self setView:v];
}
然后我就从这里想以一个IBAction
口,因为这样,但使用此代码时的Xcode不承认我的getter/setter方法在我的自定义类:
- (IBAction)setRingColor:(id)sender
{
if ([sender selectedSegmentIndex] == 0)
{
[self.view setCircleColor:[UIColor redColor]];
}
}
我怎么能将此传达给我的自定义UIView
?
感谢 伟大的答案 – 2012-07-21 00:46:11
此外,只要该视图的班上总是会对该控制器的所有实例一样,你不妨写一个类型细化类别重新定义了'view'财产具有更具体的类型。这有助于避免糟糕的投射。 – 2012-07-21 03:36:09