Summary of the Open course for IOS development at Stanford University

Source: Internet
Author: User
Tags ruby on rails

Objective

The most famous tutorial on iphone development is the "Open iphone Development Course" released by Stanford University. This public course, formerly known as the IPhone Development tutorial, was introduced this year due to the popularity of tablets, and has also been added to the ipad development-related curriculum. In the NetEase open class, there is a 2010-year video of the tutorial, and the front 15 set with Chinese subtitle files, very suitable for beginners to learn.

By the way, the 28 episodes of NetEase's Open class do not really need to be read all about. The real lesson is only 12 episodes ahead. The following courses invite celebrities from the industry to tell them about their successful apps and the students ' works, but they don't look at them. So let's not be frightened by the 28 episodes so much.

Since the release of IOS5 and Xcode4 in the past year, Apple has improved the original development environment Xcode and the development language objective-c, so much of the original tutorial is no longer applicable. For example, the new XCODE4 integrates Interface Builder into Xcode, the entire IDE layout and shortcut keys are completely different, such as Apple's reference to Objective-c ARC and Storyboard, which makes the app much more programmatic. 。

Happily, Stanford University recently updated the 2011 Fall Video of the public course, free of charge: http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewPodcast?id= 480479762, but now the public class has not translated, can only read the original English. The new curriculum is a lot shorter than it used to be, with only 9 lessons. I probably looked at it quickly and summed up some tips for everyone.

MVC mode for IOS

The MVC pattern is standard for the design patterns used by client-side class programs. iOS has its own specifications and conventions for the mutual invocation of model, View, and Controller, and in the first lesson of the Open class, it explains how to apply the MVC pattern to IOS development. The main content is shown in the diagram below (the picture is from page 37th of the supporting PDF of the first lesson of the public lesson):

Let me explain the meaning of this picture in detail below.

    • The green arrows in the diagram first indicate a direct reference. Direct referencing intuitively, it means that you need to include the declaration header file of the reference class and the instance variables of the class. As you can see, only the Controller has a direct reference to the Model and View. The direct reference to View is embodied in Iboutlet.

    • Then we see how the view communicates to the Controller. For this, there are 3 common patterns in IOS:

      1. Sets the Action Target for the View. If you set UIButton's Touch up inside Action Target.
      2. Set the delegate of the View, such as uialertviewdelegate, uiactionsheetdelegate, etc.
      3. Set the data source for the View, such as Uitableviewdatasource.
        With these 3 modes, the View achieves the ability to communicate with the controller without having to know who is the purpose of the controller and decoupling it from the controller.
    • Finally we look at Model. The Model has a similar figure on the diagram with a Notification & KVO next to the signal tower. This shows that Model mainly communicates with Controller through Notification and KVO. About Notification, I wrote a template code snippet as follows: (about the management of code snippets, I recommend you look at another article I wrote: Using Github to manage code snippets in Xcode4

//Monitoring Notifications[[nsnotificationcenter Defaultcenter] Addobserver: self selector:@selector(<  #methodName #>) name:kloginnotification Object:nil]; //Cancel monitoring[[nsnotificationcenter Defaultcenter] Removeobserver:self];//Send notifications nsdictionary * userInfo = [nsdictionary dictionarywithobject:[nsnumber Numberwithint:forkey:@ "code"];[[nsnotificationcenter defaultcenter] postnotificationname:<#notification_name #> object: Self userinfo:userinfo]; 

Therefore, for beginners, it is very difficult to use the MVC model correctly, recall that we used to do the company's IPhone version of a product, there are some model layer directly dependent on the Controller layer, such as the model layer update data failed, directly call the controller layer display A failed prompt interface. This hierarchy is unclear, which makes us very painful when we do the ipad version. Finally we did the code refactoring, the Model changes are used Notification to complete, making the ipad version of the development of a lot easier.

Convention about synthesize

"Convention over Configuration" (Convention over config) has made Ruby on Rails, and IOS has many programming conventions. There is no benefit to these conventions alone, and the biggest benefit of the Convention is that if everyone follows it, then the code style tends to be consistent and you can easily read or modify someone else's code.

We can see the following code from page 50th of PPT in the first lesson:

As you can see, this course recommends that you set an underscore prefix for the property when you use the synthesize keyword. I've also seen some open-source projects for the IPhone, such as Facebook's open source Three20, and it's a convention that follows.

Other engagements include:

    • Methods starting with new, copy, and Alloc should be release by the caller, while the other methods return a Autorelease object.
    • Usually the bar at the top of the IPhone should use the Uinavigation control, and the bar at the bottom should use the Uitoolbar control.
    • All UI actions should be performed on the main thread (UI thread). This does not seem to be an agreement, but many students do not know, also written here.
UIView

The beginning of the interface between the jump very do not understand, and later found that is actually very simple, is a layer of a stacked up View. Click on a button from view a to jump to view B, is actually the view B "cover" on View A.
There are a lot of ways to cover, and there are 2 common methods:

One. Use Uinavigationcontroller to push the View B in.

[self. Navigationcontroller pushviewcontroller:nextview Animated:YES];

Two. Use the Presentmodalviewcontroller method to cover the View B above.

[ self presentmodalviewcontroller:nextview animated:YES];

In addition, there is a cottage method, that is, view A and view B are added to the Appdelegate class of Self.window on the Addsubview. You can then call Bringsubviewtofront to show the view B as follows:

//APPDELEGATE.M class [Self. window ADDSUBVIEW:VIEWB]; [Self. window Addsubview:viewa]; //Call when needed [Self. window BRINGSUBVIEWTOFRONT:VIEWB];

It says a jump between the interfaces. For an interface, the layout of its controls is actually a stack, the reason is that if the 2 control if there are overlapping parts, then the above control will cover the following.

Nib File

The Nib file is actually an internal format of XML, and it does not compile itself into any binary code. So if you use IFile and other software on the IPhone to see some of the installed software directory, you can see a lot of nib end of the file, these are the software's interface files. Although the XML has undergone some compression transformations, we can still see some information, such as which system controls it uses, and so on.

The Nib file just started to give me a sense of mystery, and later found that it is actually used for visual editing of the View class. One of the File ' s Owner columns is used to represent the Controller class for this View. Typically, the controller class will have a variable named view that points to the instance of the view, and we can also create multiple Iboutlet variables that point to the control on the view to do some control on the interface.

There is also a benefit on Interface Builder that it is convenient to bind the event of the View to the Controller's ibaction. Just hold down the CTRL key and drag from the control to the File's Owner column to see a list of methods that can be bound. In fact, this simply simplifies our work, and if we completely abandon Interface Builder, we can do the same. I know some IOS development departments in the industry, in order to collaborate more convenient, it is mandatory not to allow the use of Interface Builder, all interface work is done in the code. If you have read the Nib file with a text editor, you can understand that it makes sense to do so. Because if 2 edit an interface file at the same time, then the likelihood of conflict is 100%, and, from SVN's conflicting information, you can't fix it at all. The following code demonstrates how to add a control without Interface Builder and bind UI events.

//Sampleviewcontroller.m Viewdidload method Fragment//Add Table View control UITableView * TableView = [[uitableview alloc] initWithFrame:cgrectmake(0, 0, (+ )];[self. View Addsubview:tableview];tableView. Delegate = self;[TableView release];//Add Button controlSelf  . Button = [[[UIButton alloc] initWithFrame:cgrectmake(0, 0 , (+ )] [autorelease];[self. View addsubview:self. Button];//Bind event[self. Button addTarget: Self action:@selector(buttonpressed) forControlEvents: (uicontroleventtouchupinside)];
Summarize

In general, it is easier to learn IOS development. I spent about one months studying the development of the iPhone and I could learn it while I was doing it.

Apple's design is very friendly to developers, often using the appropriate controls, without worrying about the underlying details. Unlike the development of Android, a moment to consider different phone resolution is not the same, a while to consider some are not touch screen, and then found that a cell phone CPU memory is too weak to run up, need to optimize the program. In addition, OBJECTIVE-C is much simpler and more powerful than the C + + language, so it's easy to be an IOS developer.

To mention the uncomfortable place, is the IOS development related Chinese information is too few. To learn it, you'll need to look at Apple's official English documents as well as the WWDC conference video, and ask questions on StackOverflow. This may be an obstacle for students who are not very good at English. But in turn, after the habit, through this exercise their English level, is also a big gain.

Summary of the Open course for IOS development at Stanford University

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.