gpt4 book ai didi

ios - Uinavigation Controller 问题

转载 作者:行者123 更新时间:2023-11-28 21:37:13 25 4
gpt4 key购买 nike

您好,我在 iOS 中以编程方式创建了 UInavigation Controller ,但问题是当我移动到下一个 View Controller 时,我指向同一屏幕。我创建了另一个名称为 InfoView 的 View ,但是当我推送到 InfoView 它显示与我在 ViewController 中创建的按钮相同的屏幕。

#import "AppDelegate.h"
#import "ViewController.h"

@interface AppDelegate ()
{
UINavigationController *navigation;

}
@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

navigation = [[UINavigationController alloc] initWithRootViewController:[[ViewController alloc] init]];
self.window.rootViewController = navigation;

[self.window makeKeyAndVisible];
return YES;
}


#import "ViewController.h"
#import "InfoView.h"

@interface ViewController ()
{
UIButton *RealVideo,*listen,*Readmat,*Look,*DiveIn;

}
@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.view.backgroundColor=[UIColor whiteColor];
[self designDeclare];
}
-(void)designDeclare{

RealVideo=[UIButton buttonWithType:UIButtonTypeCustom];
RealVideo.frame=CGRectMake(10,self.view.frame.size.height*0.2, CGRectGetWidth(self.view.frame)-20, CGRectGetHeight(self.view.frame)/7);
[RealVideo addTarget:self action:@selector(real:) forControlEvents:UIControlEventTouchUpInside];
[RealVideo setTitle:@"Real Video" forState:UIControlStateNormal];
RealVideo.backgroundColor=[UIColor colorWithRed:0.744f green:0.000f blue:0.000f alpha:1.00f];
[self.view addSubview:RealVideo];

listen=[UIButton buttonWithType:UIButtonTypeCustom];
listen.frame=CGRectMake(CGRectGetMinX(RealVideo.frame),CGRectGetMaxY(RealVideo.frame)+20, CGRectGetWidth(RealVideo.frame), CGRectGetHeight(RealVideo.frame));
// [listen addTarget:self action:@selector(Listen:) forControlEvents:UIControlEventTouchUpInside];
[listen setTitle:@"Listen" forState:UIControlStateNormal];
listen.backgroundColor=[UIColor purpleColor];
[self.view addSubview:listen];

Readmat=[UIButton buttonWithType:UIButtonTypeCustom];
Readmat.frame=CGRectMake(CGRectGetMinX(RealVideo.frame),CGRectGetMaxY(listen.frame)+20, CGRectGetWidth(RealVideo.frame), CGRectGetHeight(RealVideo.frame));
// [Readmat addTarget:self action:@selector(Listen:) forControlEvents:UIControlEventTouchUpInside];
[Readmat setTitle:@"Reading Material" forState:UIControlStateNormal];
Readmat.backgroundColor=[UIColor colorWithRed:0.000f green:0.412f blue:0.851f alpha:1.00f];
[self.view addSubview:Readmat];

Look=[UIButton buttonWithType:UIButtonTypeCustom];
Look.frame=CGRectMake(CGRectGetMinX(RealVideo.frame),CGRectGetMaxY(Readmat.frame)+20, CGRectGetWidth(RealVideo.frame), CGRectGetHeight(RealVideo.frame));
[Look addTarget:self action:@selector(Look) forControlEvents:UIControlEventTouchUpInside];
[Look setTitle:@"Look" forState:UIControlStateNormal];
Look.backgroundColor=[UIColor colorWithRed:0.400f green:1.000f blue:0.400f alpha:1.00f];
[self.view addSubview:Look];

DiveIn=[UIButton buttonWithType:UIButtonTypeCustom];
DiveIn.frame=CGRectMake(self.view.frame.size.width*0.7,CGRectGetMaxY(Look.frame)+20, CGRectGetWidth(RealVideo.frame)/4,CGRectGetHeight(RealVideo.frame)/1.5);
[DiveIn setTitle:@"Dive In" forState:UIControlStateNormal];
DiveIn.backgroundColor=[UIColor colorWithRed:0.941f green:0.471f blue:0.353f alpha:1.00f];
[self.view addSubview:DiveIn];

}

-(void)real:(id)sender{



}

-(void)Look{

InfoView *infoVC=[[InfoView alloc]init];
[self.navigationController pushViewController:infoVC animated:YES];
}

This is my firstView controller and Second viewcontroller **InfoView**[![][1] ] 1

最佳答案

导航 Controller 像堆栈一样工作,因此您可以像堆栈在现实世界中的行为一样推送和弹出 View Controller 。将导航 Controller 想象成一堆 View Controller ,因此您实际上不能添加 UIView,但您想要做的是将 uiview 作为 subview 添加到 View Controller 中并推送该 View 使用一个简单的方法将 Controller 添加到导航 Controller 堆栈中:

[navigationcontroller pushViewController:aViewcontroller];

请通读Apple Documentation了解更多信息。

关于ios - Uinavigation Controller 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33431074/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com