XibDemo

时间:2023-03-09 15:39:36
XibDemo

//
//  MyviewViewController.h
//  XibDemo
//
//  Created by hehe on 15/9/21.
//  Copyright (c) 2015年 wang.hehe. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface MyviewViewController : UIViewController

@property (weak, nonatomic) IBOutlet UIButton *Go;

- (IBAction)onclic:(id)sender;

@property (weak, nonatomic) IBOutlet UITextField *textfield1;

@property (weak, nonatomic) IBOutlet UIWebView *web;
@end

//
//  MyviewViewController.m
//  XibDemo
//
//  Created by hehe on 15/9/21.
//  Copyright (c) 2015年 wang.hehe. All rights reserved.
//

#import "MyviewViewController.h"

@interface MyviewViewController ()

@end

@implementation MyviewViewController

- (void)viewDidLoad {
    [super viewDidLoad];

}

- (IBAction)onclic:(id)sender {
    
    NSURL *url = [NSURL URLWithString:_textfield1.text];
    
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    
    [_web loadRequest:request];
    
    [_textfield1 resignFirstResponder];
}
@end

XibDemo

XibDemo

//在appdelegate中的代码

//
//  AppDelegate.m
//  XibDemo
//
//  Created by qianfeng on 15/9/21.
//  Copyright (c) 2015年 qianfeng. All rights reserved.
//

#import "AppDelegate.h"
#import "MyviewViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

- (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];
    
    //    ViewController *vc = [[ViewController alloc]init];
    MyviewViewController *vc = [[MyviewViewController alloc] initWithNibName:@"MyviewViewController" bundle:nil];
    
    self.window.rootViewController = vc;
    [self.window makeKeyAndVisible];
    
    return YES;
}

@end