如何从UIViewController调用UIView子类方法?

时间:2012-07-21 00:19:46

标签: objective-c uiview uiviewcontroller

在我的HypnosisViewController.m我有这个代码,用于向窗口添加UIView子类HypnosisView。我的目标是在UIColor circleColor控件更改其值时设置HypnosisView实例的属性UISegmented

- (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

1 个答案:

答案 0 :(得分:2)

您必须将其向下转换为派生类型。

[((HypnosisView *)self.view) setCircleColor:[UIColor redColor]];
相关问题