//在APPDelegate.h中,即项目的入口部分
在岚县等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供成都网站设计、成都网站建设 网站设计制作按需定制开发,公司网站建设,企业网站建设,成都品牌网站建设,成都全网营销推广,外贸网站制作,岚县网站建设费用合理。//didFinishLaunchingWithOptions该方法表示APP启动完毕,接下来进入自定义界面
//如下MyViewController是自定义的类,即一个界面实现UIViewController接口
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window.backgroundColor = [UIColor whiteColor]; MyViewController *myController = [[MyViewController alloc] init]; UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:myController]; self.window.rootViewController = navController; [self.window makeKeyAndVisible]; return YES; }
//MyViewController.h //定义四个控件 @interface MyViewController : UIViewController @property (strong, nonatomic) UILabel *labelNum; @property (strong, nonatomic) UILabel *labelPwd; @property (strong, nonatomic) UITextField *fieldNum; @property (strong, nonatomic) UITextField *fieldPwd; @end //MyViewController.m - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.labelNum = [[UILabel alloc] init]; self.labelNum.frame = CGRectMake(100, 100, 50, 20); self.labelNum.text = @"Num: "; self.fieldNum = [[UITextField alloc] init]; self.fieldNum.frame = CGRectMake(150, 100, 100, 20); self.fieldNum.borderStyle = UITextBorderStyleRoundedRect; self.labelPwd = [[UILabel alloc] init]; self.labelPwd.frame = CGRectMake(100, 150, 50, 20); self.labelPwd.text = @"Pwd: "; self.fieldPwd = [[UITextField alloc] init]; self.fieldPwd.frame = CGRectMake(150, 150, 100, 20); self.fieldPwd.borderStyle = UITextBorderStyleRoundedRect; UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; btn.frame = CGRectMake(100, 200, 80, 20); btn.backgroundColor = [UIColor grayColor]; [btn setTitle:@"login" forState:UIControlStateNormal]; //设置按钮监听事件,监听方法为login [btn addTarget:self action:@selector(login) forControlEvents:UIControlEventTouchDown]; [self.view addSubview:self.labelNum]; [self.view addSubview:self.fieldNum]; [self.view addSubview:self.labelPwd]; [self.view addSubview:self.fieldPwd]; [self.view addSubview:btn]; }
//页面跳转,并传递参数
-(void) login{ NSLog(@"login"); NSString *num = self.fieldNum.text; NSString *pwd = self.fieldPwd.text; if([num isEqualToString:@"123"] == TRUE){ NSLog(@"yes"); //初始化要跳转的界面 MainViewController *mm = [[MainViewController alloc] init]; //把账号密码传递到下个界面 [mm initData:num two:pwd]; //开始跳转 [self.navigationController pushViewController:mm animated:FALSE]; }else{ NSLog(@"error"); } }
//MainViewController.h
@interface MainViewController : UIViewController //@property( nonatomic) NSString //传递两个参数a、b NSString 类型 -(void) initData:(NSString *) a two:(NSString *) b; @end
//接收参数,并保存 -(void) initData:(NSString *) a two:(NSString *) b{ self.num = a; self.pwd = b; NSLog(@"%@,%@", self.num, self.pwd); }
//效果图
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。