我再次感到愚蠢,但我无法在项目的子视图之间来回导航。只要继续前进,我就可以添加任意数量的子视图,但是一旦我想回到以前访问过的视图之一,我就有问题了……这是我的简化代码:
C4Workspace.h
#import "C4CanvasController.h"
#import "FirstView.h"
@interface C4WorkSpace : C4CanvasController{
FirstView *firstView;
}
@end
C4Workspace.m
#import "C4Workspace.h"
@implementation C4WorkSpace
-(void)setup {
firstView=[FirstView new];
firstView.canvas.frame=CGRectMake(0, 0, self.canvas.width, self.canvas.height);
firstView.canvas.userInteractionEnabled=YES;
[firstView setup];
firstView.mainCanvas=self.canvas;
[self.canvas addSubview:firstView.canvas];
}
@end
第一视图.h
#import "C4CanvasController.h"
#import "SecondView.h"
@interface FirstView : C4CanvasController{
C4Label *goToSecondView;
SecondView *secondView;
}
@property (readwrite, strong) C4Window *mainCanvas;
@end
第一视图.m
#import "FirstView.h"
@implementation FirstView
-(void)setup{
goToSecondView=[C4Label labelWithText:@"go to second View"];
goToSecondView.origin=CGPointMake(20, 50);
[self.canvas addLabel:goToSecondView];
[self listenFor:@"touchesBegan" fromObject:goToSecondView andRunMethod:@"goToSecondView"];
}
-(void)goToSecondView{
[goToSecondView removeFromSuperview];
C4Log(@"second view");
secondView=[SecondView new];
secondView.canvas.frame=CGRectMake(0, 0, self.canvas.width, self.canvas.height);
secondView.canvas.userInteractionEnabled=YES;
[secondView setup];
secondView.mainCanvas=self.canvas;
[self.canvas addSubview:secondView.canvas];
}
@end
第二视图.h
#import "C4CanvasController.h"
#import "FirstView.h"
@interface SecondView : C4CanvasController{
C4Label *goToFirstView;
FirstView *firstView;
}
@property (readwrite, strong) C4Window *mainCanvas;
@end
第二视图.m
#import "SecondView.h"
@implementation SecondView
-(void)setup{
goToFirstView=[C4Label labelWithText:@"go to First View"];
goToFirstView.origin=CGPointMake(20, 50);
[self.canvas addLabel:goToFirstView];
[self listenFor:@"touchesBegan" fromObject:goToFirstView andRunMethod:@"goToFirstView"];
}
-(void)goToFirstView{
[goToFirstView removeFromSuperview];
C4Log(@"first view");
firstview=[FirstView new];
firstview.canvas.frame=CGRectMake(0, 0, self.canvas.width, self.canvas.height);
firstView.canvas.userInteractionEnabled=YES;
[firstView setup];
firstView.mainCanvas=self.canvas;
[self.canvas addSubview:firstView.canvas];
}
@end