2014-05-21 1 views
1

바로 iOS dev에서 휴식을 취하고 다시 믹스에 들어갔습니다.Storyboard 또는 XIB없이 Xcode에서보기 컨트롤러를 만드는 방법과 루트보기로 AppDelegate에 구성하는 방법

xib 또는 스토리 보드 의존성없이 프로그래밍 방식으로 UIWebView가 포함 된 View Controller를 만들고 싶지만 내 View Controller를 표시하는 AppDelegate를 얻는 방법을 사랑이나 돈으로 기억할 수 없습니다.

는 모든 문서에서 내가 찾을 수있는 모든 내 AppDelegate에

self.window = [[ViewController alloc] initWithNibName:@"blah" bundle: nil]; 

에서 아래에 배치됩니다하지만 어떤 XIB의 제의 ViewController에 관련이없는 것처럼이 쓸모가있을 것입니다 파일.

누군가 나를 올바른 길로 되돌릴 수 있습니까?

감사

AppDelegate.m에서
+0

전혀 관련이없는 마법입니다. 사용자 정의 VC를 정의하고 XIB에서 정의한 모든 구성 요소를 작성하는'loadView' 메소드를 갖게됩니다. 그런 다음'viewDidLoad'는 구성 요소의 크기와 위치를 적절히 조정해야합니다. 종종 이것은 XIB가 잘 표현하지 못하는 경우 XIB를 사용하는 것보다 간단합니다. –

답변

3

:

CustomViewController *rootViewController = [CustomViewController new]; 

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
self.window.rootViewController = rootViewController; 
[self.window makeKeyAndVisible]; 

CustomViewController.m 재정에서 :

- (void)loadView { 
    //Configure your view 
    self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 

    //other stuff 
    [self.view setBackgroundColor:[UIColor redColor]]; 

    UIButton *button = /* alloc init etc. */ 
    [self.view addSubview:button]; 
} 
+0

당신의 제안을 시도해 주셔서 감사 드리며, 검은 화면 (콘솔에 오류가 없습니다)이 생겼습니다. 제 코드 세트를 추가하면 도움이 될 것 같아요 ... – Amraj

+0

AppDelegate.m :'- (BOOL) 응용 프로그램 : (UIApplication *) application didFinishLaunchingWithOptions : (NSDictionary *) launchOptions { ViewController * rootViewController = [ViewController new]; self.window.rootViewController = rootViewController; [window makeKeyAndVisible]; return YES; } ViewController.m 아래의 ' – Amraj

+0

: '- (void) loadView { [super viewDidLoad]; self.view = [[UIView alloc] initWithFrame : [[UIScreen mainScreen] bounds]]; webView = [[UIWebView alloc] initWithFrame : CGRectMake (0, 0, 320, 480)]; [webView loadRequest : [NSURLRequest requestWithURL : [NSURL URLWithString : @ "http://www.google.com"]]]; [self.view addSubview : webView]; } ' – Amraj

0

클래스의 ViewController : UIViewController에, UIPageViewControllerDataSource, CLLocationManagerDelegate, UITextFieldDelegate, UITableViewDataSource, UITableViewDelegate { //를 만들 위치 관리자 let locationManager = CLLocationManager()

//menu button 
@IBOutlet weak var menu: UIBarButtonItem! 

@IBOutlet weak var locationTextField: UITextField!{ 
    didSet { 
     locationTextField.delegate = self 
     locationTextField.text = "" 
    } 
} 

func numberOfSectionsInTableView(tableView: UITableView) -> Int { 
    return 1 
} 

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    return globalSearchText.searchArrayLocation.count 
} 

func tableView(tableView: UITableView, performAction action: Selector, forRowAtIndexPath indexPath: NSIndexPath, withSender sender: AnyObject?) { 
    locationTextField.text = globalSearchText.searchArrayLocation[indexPath.row] 
} 
관련 문제