An overview,

Officially started iOS learning plan, or as always busy, so it was done over the weekend.

Spent a day learning iOS on Saturday and is feeling fine, thanks to an unknown kid.

This is his BLOG www.samirchen.com/

The reason why the following is not in accordance with ** entry routine to write, is that I think the above children’s shoes have written very well, the idea is very clear, I am difficult to surpass, and then to write can only be copied.

But the directory structure is borrowed, as illustrated here.

Second, practice

1. Create an iOS project

1.1 install Xcode

Xcode download: (1) AppStore download (2) apple.developer.com download

To install Xcode, click the download and follow the instructions.

1.2 Creating an empty project
1.3 Adding an interaction event

For the simplest scenario, create a UIButton and click UIButton to bring up a prompt box.

There are two ways to do this:

(1) In storyboard mode, drag a UIButton control to the storyboard, tap the pop-up prompt box with both fingers, select the Touch Up Inside click event, drag it to the viewController.m code editor, and edit the code. The details are shown in the figure below:

(2) Custom View method of pure code writing.

Reference: www.samirchen.com/ios-start-1…

2. Manage third-party libraries

In iOS, library dependencies are managed through CocoaPods.

2.1 installation CocoaPods

Because CocoaPods needs to be downloaded and installed through rubygem command, and ruby’s software source https://rubygems.org is blocked because it uses Amazon’s cloud service, you can switch to the Taobao source for installation.

sudo gem sources -a https://ruby.taobao.org/
sudo gem sources -r https://rubygems.org/
sudo gem sources -l

sudo gem update
sudo gem install -n /usr/local/bin cocoapods -v 0.39
pod setup
pod --version
Copy the code

2.2 Include CocoaPods and third-party libraries in your current project

Here we use SVProgressHUD and navigation.

SVProgressHUD is a prompt box similar to the ProgressDialog in Android

Navigation is a lightweight layout framework with its own description syntax that incorporates automatic layout with a more elegant chained syntax

Create a Podfile in the project root directory and add the following configuration to the file:

The source 'https://github.com/CocoaPods/Specs.git' platform: ios, "8.0" target "iOSStartDemo" do pod 'SVProgressHUD', '1.1.3' pod 'navigation ', '0.6.3' endCopy the code

Then run the following command to install the third-party dependencies:

After the installation is successful, there will be several more files in the project root directory. Open the.xcworkspace file, restart the workspace, and continue.

2.3 Use third-party libraries in your code

Reference: www.samirchen.com/ios-start-2…

3. Implement a multi-page App

3.1 Project directory structure adjustment

Why should you consider directory structure changes when learning iOS for the first time?

Well, learning iOS for the first time does not mean that the foundation is zero, and the previous coding experience can be flexibly used to learn new technologies.

IOS officially uses MVC architecture, similar to Android. Usually a complete project consists of basic functional modules, basic business modules, various business modules and resource files. Different business modules are placed under different packages, and each business module uses the MVC pattern. There will be less coupling and the structure will be clear.

As follows:

In the actual operation process, the senior students try to adjust the directory structure in two ways:

(1) New Group mode

In Xcode, tap the project home directory with both fingers, and select New Group to create business folders.

This worked fine, but when I went to the Finder, I didn’t find the folder I had created. All the files were in one directory, so I thought something was wrong. After checking the demo, I found that someone else’s had a folder, so I googled it and tried the method (2).

(2) Create an entity folder

Create the corresponding entity folder directly in the Finder location.

I can see the corresponding folder in Xcode, but when I start to run, I can’t find ** viewController.h, this class clearly exists, I checked several times. I compared the difference between method (2) and method (1) and found that the folder of method (2) is blue and the folder of method (1) is yellow. I started googling again to find a way to turn blue yellow. I just dragged the solid folder in the Finder to the corresponding location in Xcode and deleted the blue folder in Xcode.

The results work as expected, and folders are now visible in Both Xcode and Finder, so you don’t have to worry about all the business classes stacked together anymore.

The renderings are as follows:

The following is a summary:

There is an important concept in Android called package, and different business modules are usually placed in different packages. A reference to a class also needs to import the package that the class belongs to, or precede the class name with the package name.

However, iOS references to a class simply import the header file of that class, such as import ** viewController.h, without the package name.

Group is somewhat similar to Package, but it is just a Group, a virtual folder in the Xcode environment, and not actually visible in the Finder.

The entity folder created in Finder is not recognized by Xcode. Xcode only recognizes virtual folders, but you can get virtual folders by dragging the physical folders in the Finder to the corresponding location in Xcode, where the virtual and physical folders correspond.

The following is an excerpt:

Common page containers are UITabBarController and UINavigationController.

UITabBarController is an array that manages all UIViewControllers in a container

UINavigationController is a stack that manages all UIView Controllers in the container

These two containers can be nested, usually UITabBarController as the primary container and UINavigationController as the secondary container

As shown below:

The entry program is MXJAppDelegate, which is similar to the Application class in Android

I looked again. There was a main.h file in the main directory and a main.m file in the Supporting Files directory, and MXJAppDelegate was called in both Files. Well, it turns out that the iOS development language Objective-C is based on C and uses Main as the real entry point for programs.

3.3 use UITableView

UITableView is a ListView, similar to Android ListView and RecyclerView

Reference: www.samirchen.com/ios-start-3…

Third, summary

1. Each class consists of ***.h and ***.m2 files. Android only has.java files

2. Main. m is the real entry of the program, and its AppDelegate is the Objective-C code entry. Corresponds to Application in Android

3. There are two ways to create a View: storyboard and code customization, which correspond to the.xml layout and code customization in Androud

IOS library dependencies use CocoaPods Android library dependencies use Gradle

5. There is no package in iOS, only the concept of Group. Group is a virtual folder under Xcode, not a physical folder. By creating a physical folder in the Finder and dragging it to the corresponding directory in Xcode, you can map the physical folder and virtual folder to the concept of Package in Android. You need to import package to reference a class

6. A preliminary understanding of several common controls in iOS: SVProgressHUD is a notification box similar to the ProgressDialog (2) navigation in Android. SVProgressHUD is a lightweight layout framework with its own description syntax and a more elegant chain syntax for automatic layout

Native: UIButton UITableView, UITabBarController, UINavigationController, UIViewController UIButton button (1), Similar to Button (2) UITableView list View in Android, Similar to the Android ListView and RecyclerView (3) UITabBarController management TAB a controller (4) UINavigationController interface navigation controller, can also be understood as interface routing control? (5) UIViewController is a basic class that manages a View. Its parent can be UITabBarController, UINavigationController, etc.

Fourth, to the readers

How do you learn a new skill?

(1) Prerequisite:

Because of my Android development experience, I am not and should not consider myself zero-based when learning new technology iOS

Android developers learn iOS only to broaden their knowledge, not to the same standards as iOS developers, simple iOS App development, know some basic knowledge

(2) Learning methods:

Learn by doing.

Since you already have Android development experience, the first step should be to set up an environment that can run a Hello World application

Next, according to the introductory tutorial, do a simple small function, according to the example of the side can be knocked, familiar with the use of Xcode, a preliminary feel of the iOS program structure, a preliminary understanding of several common controls.

Next, I thought I’d find a moderately difficult iOS project on Github, where I could learn Objective-C syntax and various controls in iOS

The above for other new technology learning, should also have a certain degree of guidance significance

The above only represent personal opinion, no absoluteness and authority, welcome to ridicule

demo

Reference documentation

www.samirchen.com/ios-index/ www.cocoachina.com/ios/2016030…

Welcome to pay attention to my public number: senior IT column