{"id":565,"date":"2018-02-23T23:40:04","date_gmt":"2018-02-23T15:40:04","guid":{"rendered":"http:\/\/60.205.208.74\/2018\/02\/23\/ios%e5%af%bc%e8%88%aa%e6%a0%8f\/"},"modified":"2018-02-23T23:40:04","modified_gmt":"2018-02-23T15:40:04","slug":"ios%e5%af%bc%e8%88%aa%e6%a0%8f","status":"publish","type":"post","link":"https:\/\/www.puzi7.net\/?p=565","title":{"rendered":"iOS\u5bfc\u822a\u680f"},"content":{"rendered":"<span itemprop=\"description\"><div class=\"article-body\">\n<div class=\"article-intro\" id=\"content\">\n<h2>IOS\u5bfc\u822a\u680f\u7684\u4f7f\u7528<\/h2>\n<p>\u5bfc\u822a\u680f\u5305\u542b\u5bfc\u822a\u63a7\u5236\u5668\u7684\u5bfc\u822a\u7684\u6309\u94ae\u3002\u5728\u5bfc\u822a\u680f\u4e2d\u7684\u6807\u9898\u662f\u5f53\u524d\u89c6\u56fe\u63a7\u5236\u5668\u7684\u6807\u9898\u3002<\/p>\n<p><\/p>\n<hr>\n<h2>\u793a\u4f8b\u4ee3\u7801\u548c\u6b65\u9aa4<\/h2>\n<p>1.\u521b\u89c6\u56fe\u5e94\u7528\u7a0b\u5e8f<\/p>\n<p>2.\u00a0\u73b0\u5728\uff0c\u9009\u62e9\u5e94\u7528\u7a0b\u5e8f\u00a0Delegate.h\u00a0\uff0c\u6dfb\u52a0\u5bfc\u822a\u63a7\u5236\u5668\u7684\u5c5e\u6027\uff0c\u5982\u4e0b\u6240\u793a:<\/p>\n<pre>\n#import &lt;UIKit\/UIKit.h&gt;\n\n@class ViewController;\n\n@interface AppDelegate : UIResponder &lt;UIApplicationDelegate&gt;\n\n@property (strong, nonatomic) UIWindow *window;\n\n@property (strong, nonatomic) ViewController *viewController;\n\n@property (strong, nonatomic) UINavigationController *navController;\n\n@end<\/pre>\n<p>3. \u66f4\u65b0\u5e94\u7528\u7a0b\u5e8f: didFinishLaunchingWithOptions:\u65b9\u6cd5\uff0c\u5728AppDelegate.m\u6587\u4ef6\u5206\u914d\u7684\u5bfc\u822a\u63a7\u5236\u5668\uff0c\u5e76\u4f7f\u5176\u6210\u4e3a\u7a97\u53e3\u7684\u6839\u89c6\u56fe\u63a7\u5236\u5668\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions\n{\n    self.window = [[UIWindow alloc] initWithFrame:\n    [[UIScreen mainScreen] bounds]];\n    \/\/ Override point for customization after application launch.\n    self.viewController = [[ViewController alloc] \n    initWithNibName:@\"ViewController\" bundle:nil];\n    \/\/Navigation controller init with ViewController as root\n    UINavigationController *navController = [[UINavigationController alloc]\n    initWithRootViewController:self.viewController];\n    self.window.rootViewController = navController;\n    [self.window makeKeyAndVisible];\n    return YES;\n}<\/pre>\n<p>4.\u73b0\u5728\uff0c\u901a\u8fc7\u9009\u62e9<b>File<\/b>\u00a0-&gt;\u00a0<b>New<\/b>\u00a0-&gt;<b>File&#8230;<\/b>\u00a0-&gt; Objective C Class\u00a0\u6dfb\u52a0\u65b0\u7684\u7c7b\u6587\u4ef6TempViewController\uff0c\u7136\u540e\u5c06\u7c7b\u547d\u540d TempViewController\u00a0\u4e0e\u00a0UIViewController\u00a0\u7684\u5b50\u7c7b\u3002<\/p>\n<p>5.\u5728ViewController.h\u4e2d\u6dfb\u52a0navButon\uff0c\u5982\u4e0b\u6240\u793a<\/p>\n<pre>\/\/ ViewController.h\n#import &lt;UIKit\/UIKit.h&gt;\n\n@interface ViewController : UIViewController\n{    \n    UIButton *navButton;\n}\n@end<\/pre>\n<p>6.\u73b0\u5728\u6dfb\u52a0\u65b9\u6cd5addNavigationBarItem\u5e76\u5728viewDidLoad\u8c03\u7528\u65b9\u6cd5<\/p>\n<p>7. \u4e3a\u5bfc\u822a\u9879\u521b\u5efa\u65b9\u6cd5<\/p>\n<p>8.\u00a0\u6211\u4eec\u8fd8\u9700\u8981\u521b\u5efa\u53e6\u4e00\u79cd\u65b9\u6cd5\u5230\u53e6\u4e00\u89c6\u56fe\u63a7\u5236\u5668\u00a0TempViewController\u3002<\/p>\n<p>9.\u00a0\u66f4\u65b0\u540e\u7684ViewController.m\uff0c\u5982\u4e0b\u6240\u793a:<\/p>\n<pre>\/\/ ViewController.m\n#import \"ViewController.h\"\n#import \"TempViewController.h\"\n@interface ViewController ()\n\n@end\n@implementation ViewController\n\n- (void)viewDidLoad\n{\n    [super viewDidLoad];\n    [self addNavigationBarButton];\n    \/\/Do any additional setup after loading the view, typically from a nib\n}\n\n- (void)didReceiveMemoryWarning\n{\n    [super didReceiveMemoryWarning];\n    \/\/ Dispose of any resources that can be recreated.\n}\n\n-(IBAction)pushNewView:(id)sender{\n   TempViewController *tempVC =[[TempViewController alloc]\n   initWithNibName:@\"TempViewController\" bundle:nil];\n   [self.navigationController pushViewController:tempVC animated:YES];\n}\n\n-(IBAction)myButtonClicked:(id)sender{\n   \/\/ toggle hidden state for navButton\n   [navButton setHidden:!nav.hidden];\n}\n\n-(void)addNavigationBarButton{\n   UIBarButtonItem *myNavBtn = [[UIBarButtonItem alloc] initWithTitle:\n   @\"MyButton\" style:UIBarButtonItemStyleBordered target:\n   self action:@selector(myButtonClicked:)];\n   \n   [self.navigationController.navigationBar setBarStyle:UIBarStyleBlack];\n   [self.navigationItem setRightBarButtonItem:myNavBtn];\n   \n   \/\/ create a navigation push button that is initially hidden\n   navButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];\n   [navButton setFrame:CGRectMake(60, 50, 200, 40)];\n   [navButton setTitle:@\"Push Navigation\" forState:UIControlStateNormal];\n   [navButton addTarget:self action:@selector(pushNewView:) \n   forControlEvents:UIControlEventTouchUpInside];\n   [self.view addSubview:navButton];\n   [navButton setHidden:YES];\n}\n@end<\/pre>\n<p>10.\u00a0\u73b0\u5728\u5f53\u6211\u4eec\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\u65f6\u6211\u4eec\u5c31\u4f1a\u5f97\u5230\u4e0b\u9762\u7684\u8f93\u51fa<\/p>\n<p><img decoding=\"async\" alt=\"iOS Tutorial\" src=\"http:\/\/www.tutorialspoint.com\/ios\/images\/navigationBarOutput.jpg\" data-pinit=\"registered\"><\/p>\n<p>11.\u00a0\u5355\u51fb\u00a0MyButton\u00a0\u5bfc\u822a\u6309\u94ae\uff0c\u5207\u6362\u5bfc\u822a\u6309\u94ae\u53ef\u89c1\u6027<\/p>\n<p>12.\u00a0\u5355\u51fb\u5bfc\u822a\u6309\u94ae\uff0c\u663e\u793a\u53e6\u4e00\u4e2a\u89c6\u56fe\u63a7\u5236\u5668\uff0c\u5982\u4e0b\u6240\u793a<\/p>\n<p><img decoding=\"async\" alt=\"iOS Tutorial\" src=\"http:\/\/www.tutorialspoint.com\/ios\/images\/navigationBarActionOutput.jpg\" data-pinit=\"registered\"><\/p>\n<\/p><\/div>\n<\/p><\/div>\n<span>","protected":false},"excerpt":{"rendered":"<p class=\"excerpt\"><span itemprop=\"description\">IOS\u5bfc\u822a\u680f\u7684\u4f7f\u7528 \u5bfc\u822a\u680f\u5305\u542b\u5bfc\u822a\u63a7\u5236\u5668\u7684\u5bfc\u822a\u7684\u6309\u94ae\u3002\u5728\u5bfc\u822a\u680f\u4e2d\u7684\u6807\u9898\u662f\u5f53\u524d\u89c6\u56fe\u63a7\u5236\u5668\u7684\u6807&hellip;<\/span><\/p>\n<p class=\"more-link-p btn-align-right\"><a class=\"green zoom-btn\" href=\"https:\/\/www.puzi7.net\/?p=565\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38,26],"tags":[74,93],"class_list":["post-565","post","type-post","status-publish","format-standard","hentry","category-ios","category-mobile","tag-ios","tag-mobile","zoom-theme-has-thumb"],"_links":{"self":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts\/565","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=565"}],"version-history":[{"count":0,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts\/565\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=565"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=565"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=565"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}