Objective c 无法将UIButtons添加到CPTGraphHostingView的superview

Objective c 无法将UIButtons添加到CPTGraphHostingView的superview,objective-c,core-plot,Objective C,Core Plot,很抱歉又问了一个基本问题。如何将UIButton添加到CPTGraphHostingView的superview?当按钮直接添加到CPTHostingView时,UIButton的标题会颠倒。我在谷歌上搜索发现,我不得不将它添加到CPTGraphHostingView的superview中 我尝试了下面的代码,但没有成功。谁能告诉我怎么做?谢谢大家! UIButton *exp = [UIButton buttonWithType:UIButtonTypeRoundedRect]; exp.fr

很抱歉又问了一个基本问题。如何将UIButton添加到CPTGraphHostingView的superview?当按钮直接添加到CPTHostingView时,UIButton的标题会颠倒。我在谷歌上搜索发现,我不得不将它添加到CPTGraphHostingView的superview中

我尝试了下面的代码,但没有成功。谁能告诉我怎么做?谢谢大家!

UIButton *exp = [UIButton buttonWithType:UIButtonTypeRoundedRect];
exp.frame = CGRectMake( 5, j*30 + 3, 100, 25 );
[exp addTarget:self action:@selector(expClicked:) forControlEvents:UIControlEventTouchUpInside];
[exp setTitle:title forState:UIControlStateNormal];

[[hostingView superview] addSubview:exp];

运行此代码时,宿主视图是否有superview?@eric我是objective-c的新手。如何检查宿主视图是否具有超级视图?这取决于您如何设置它。如果手动将宿主视图添加到其superview中,请在之后执行上述代码。否则,例如,如果宿主视图是在.xib或故事板中创建的,请确保hostingView不是nil。发现superview是nil。我再试一次。非常感谢。