Cat Share, must boutique
Original articles, welcome reprint. Reprint Please specify: Sanayu's Blog
Address: http://blog.csdn.net/u013357243?viewmode=contents
A: Brief introduction
This is the Sina Weibo iOS project, from the Dark Horse of a real-combat project. (I do not have training, purely self-study, but people should learn to be thankful, although they are buying the study materials, but drink from!! )
Mainly divided into five large modules, this time all using pure code implementation, which will use a lot of the previous learning content, if there is a duplication of knowledge points, that this knowledge point is really important, there is no time to watch video learning or training of friends, you can see the cat of this series of blogs, Cats will do their best to improve him.
What is not comprehensive, welcome to reply to me, the cat will be corrected as soon as possible.
Second: Establish project import material
The first step is to build our project, here I do not use the latest version of the Xcode6, but the use of xcode5.1, why use 5.1 instead of 6?
First: I learned the video is used xcode5.1, which is the main reason, cat as a sports student, self-study programming two years of experience is that in watching video self-study as much as possible to make their own all the same as other entities teaching, cat has been learning Android because Android SDK is different, the new fragmentation is not the same as the action in the video, which greatly strikes the enthusiasm of learning.
Second: There is a lot of business to use 5.1 or even 4.1 (according to a friend said ...) Of course, this also can be seen the main reason. But the cat suggested that when learning to a certain level, more to receive new knowledge, of course, I think the old more important, do not say that we have a cloud of Mandarin, restudying, original aim, learning solid old knowledge, new knowledge to start searching easy.
Build a project
Select Single View Application Select Next
Write the project name Cat and Cat Weibo (name whatever) Choose Next
And then it's the next step.
Because we're going to use pure code, we'll remove the other useless controllers and Main.storyboard.
Remove References means that it is only deleted in Xcode, but also in the file.
Move to Trash is represented, directly into the system trash.
Then import the footage (the picture we used) images.xcassets
Applcon inside is the picture on the home page of the mobile phone
Launchimage is the image that starts when the application loads.
For the blank position of the first picture, we can directly modify the JSON file to control, of course, directly dragged in can also (equivalent to modify JSON)
Three: Create window
Previous blogs have written about what steps the program will take when it runs.
Because we removed the Main.storyboard, this time the running program will error, we need to modify the diagram inside the main delete him, change to empty
Running the program at this time will be like this:
Wu seven or eight black ...
And then we're going to write the code in NYAPPDELEGATE.M.
- (BOOL) Application: (uiapplication*) Application Didfinishlaunchingwithoptions: (nsdictionary*) launchoptions{//1. Creating a Window Self. Window= [[UIWindowAlloc]initwithframe:[uiscreen Mainscreen]. Bounds];//2. Setting up the root controllerNytabbarviewcontroller *tabbarc = [[Nytabbarviewcontroller alloc] init]; Self. Window. Rootviewcontroller= Tabbarc;//3. display window[ Self. WindowMakekeyandvisible];return YES;}
Three simple steps, you can show it.
Write your own nytabbarviewcontroller.m
////NYTABBARVIEWCONTROLLER.M//Cat Weibo////Created by Apple on 15-6-2.//Copyright (c) 2015 Znycat. All rights reserved.//#import "NYTabBarViewController.h" #import "NYHomeViewController.h" #import "NYMessageCenterViewController.h" #import "NYDiscoverViewController.h" #import "NYProfileViewController.h" #import "NYNavigationController.h" @interface nytabbarviewcontroller ()@end @implementation nytabbarviewcontroller -(void) viewdidload{[SuperViewdidload];//1. Initialize the child controller //1. Initialize the child controllerNyhomeviewcontroller *home = [[Nyhomeviewcontroller alloc] init]; [ SelfAddchildvc:home title:@"Home"image:@"Tabbar_home"selectedimage:@"tabbar_home_selected"]; Nymessagecenterviewcontroller *messagecenter = [[Nymessagecenterviewcontroller alloc] init]; [ SelfAddchildvc:messagecenter title:@"Message"image:@"Tabbar_message_center"selectedimage:@"tabbar_message_center_selected"]; Nydiscoverviewcontroller *discover = [[Nydiscoverviewcontroller alloc] init]; [ SelfAddchildvc:discover title:@"Discovery"image:@"Tabbar_discover"selectedimage:@"tabbar_discover_selected"]; Nyprofileviewcontroller *profile = [[Nyprofileviewcontroller alloc] init]; [ SelfAddchildvc:profile title:@"I"image:@"Tabbar_profile"selectedimage:@"tabbar_profile_selected"];}/** * Add a sub-controller * * @param CHILDVC Sub-controller * @param title title * @param image Image * @param selecte DIMAGE The selected picture * /- (void) ADDCHILDVC: (Uiviewcontroller*) CHILDVC title: (NSString*) Title Image: (NSString*) Image selectedimage: (NSString*) selectedimage{//Set the text of the child controllerChildvc. Title= title;//Set Tabbar and Navigationbar text at the same time //ChildVc.tabBarItem.title = title;//Set Tabbar text //ChildVc.navigationItem.title = title;//Set Navigationbar text //Set Picture of child controllerChildvc. Tabbaritem. Image= [UIImageImagenamed:image]; Childvc. Tabbaritem. SelectedImage= [[UIImageImagenamed:selectedimage]imagewithrenderingmode:uiimagerenderingmodealwaysoriginal];//Set style of text nsmutabledictionary*textattrs = [nsmutabledictionaryDictionary]; Textattrs[nsforegroundcolorattributename] = Nycolor (123,123,123);nsmutabledictionary*selecttextattrs = [nsmutabledictionaryDictionary]; Selecttextattrs[nsforegroundcolorattributename] = [UicolorOrangecolor]; [CHILDVC. TabbaritemSettitletextattributes:textattrs Forstate:uicontrolstatenormal]; [CHILDVC. TabbaritemSettitletextattributes:selecttextattrs forstate:uicontrolstateselected];a navigation controller is packaged in a small controller that is passed in first.Nynavigationcontroller *nav = [[Nynavigationcontroller alloc] INITWITHROOTVIEWCONTROLLER:CHILDVC];//Add as a child controller[ SelfAddchildviewcontroller:nav];}/ * #pragma mark-navigation//in a storyboard-based application, you'll often want to do a little preparation before navigation-(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) sender{//Get The new view controller using [ Segue Destinationviewcontroller]. Pass the selected object to the new view Controller.} */@end
Here we use the object-oriented approach to design the code, we need a nytabbarviewcontroller, to create him, who is the most clear? Of course it was himself, so we put the code in his own. Do the refactoring of the code.
And for
"NYHomeViewController.h"
"NYMessageCenterViewController.h"
"NYDiscoverViewController.h"
"NYProfileViewController.h"
"NYNavigationController.h"
These, we first think of him as a tableviewcontroller or viewcontroller can be, is a class, has not realized the function.
The effect is this:
Cat Learning iOS Weibo project Combat (1) Weibo main frame-addition of sub-controller