(本人项目中遇到这个问题)子view添加到有controller的父view时,在点击子view中的什么东西时,如果要调用父view的controller导航push到一个新viewController,那么直接用下面的代码就可以了)
//获取view的controller
- (UIViewController *)viewController
{
for (UIView* next = [self superview]; next; next = next.superview) {
UIResponder *nextResponder = [next nextResponder];
if ([nextResponder isKindOfClass:[UIViewController class]]) {
return (UIViewController *)nextResponder;
}
}
return nil;
}
//点击按钮
-(void)buttonClick
{
PersonalController *pc=[[PersonalController
alloc]init];
[[self viewController].navigationController pushViewController:
pc animated:YES];
[pc
release];
}