这是一些代码:
ViewControllerA.h
@interface ViewControllerA: UIViewController {
NSString *myString;
}
@property (nonatomic,retain)NSString *myString;
ViewControllerA.m
@implementation ViewControllerA
@synthesize myString;
然后我在导航 Controller 中推送 ViewControllerB。当我想返回到 ViewControllerA ViewControllerB.m
-(IBAction)randomAction(id)sender {
ViewControllerA *myViewController = (ViewControllerA*)[self parentViewController]:
[myViewController setMyString:@"test"]: // HERE IS THE ERROR : "[DMINavigationController setMyString:]:unrecognized selector sent to instance"
[self.navigationController popToViewController:[[self.navigationController viewControllers] objectAtIndex:0] animated:YES]
}
为什么?错误返回到“[DMINavigationController setMyString:]”而不是我的 View Controller 是否正常?
最佳答案
我认为您对 ViewController 以及如何在 NavigationController 中正确处理它们有些困惑。
您可能从 DMINavigationController
开始,并使用 ViewControllerA
对其进行初始化。如果您推送一个新的 ViewController ViewControllerB
,父级将不是 ViewControllerA
,而是 NavigationController。
如果您想访问以前的 ViewController,您需要查询 NavigationController 的 viewControllers
属性来找到它。
你要找的VC在(index of current Object)-1
int index = [self.navigationController.viewControllers indexOfObject:self] - 1;
ViewControllerA *vcA = [self.navigationController.viewControllers objectAtIndex:index];
关于iphone - View a 中的 setter 来自 View b : unrecognized selector sent to instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12637133/