iOS Development experience Sharing

Source: Internet
Author: User

Some tips for iOS development:

1) [Multiple Threads] iOS multithreading Note that all UI actions must be on the main thread:

Any code that would update the UI should be do on the main thread. Data loading should typically is done in some background thread.

Example: [Self performselectoronmainthread: @selector (updatethumbnail:) withobject:tmpimg Waituntildone:false];

2) [Design] THREE20 is a heavyweight framework, almost itself re-implemented iOS UI components, use need to be cautious!

3) [Design] single uiviewcontroller or mutiple uiviewcontroller, need think~

4) [UI] Gets the current direction of the Ipad/iphone:

Objective C code   
    1. uiinterfaceorientation orientation = [[UIApplication sharedapplication] statusbarorientation];
    2. if (orientation = = Uiinterfaceorientationportrait | | orientation = = Uiinterfaceorientationportraitupsidedown) {
    3. ... ...
    4. } else {
    5. ... ...
    6. }

5) [Memory Management] Release a variable and set it to nil is a good habit.

Objective C code
    1. The object space of Alloc or new in Viewdidload needs to be released here.
    2. -(void) Viewdidunload {
    3. [_sushitypes release];
    4. _sushitypes = nil;
    5. }
    6. -(void) Dealloc {
    7. [_sushitypes release];
    8. _sushitypes = nil;
    9. [Super Dealloc];
    10. }

Http://www.raywenderlich.com/2657/memory-management-in-objective-c-tutorial wrote

Note that you also set the object to nil afterwards. This was a good practice, because by setting it-nil it avoids a lot of problems. Any time you call a method on a nil object, it does nothing, but if you don't set it to nil, if you tried calling a method On a deallocated the object your program should crash.

6) [other] #import and @class declaration usage

http://stackoverflow.com/questions/322597/class-vs-import/1350029#1350029 wrote three simple rules: * Only #import the Super class in header files. * #import All classes your send messages to in implementation. * Forward declarations for everything else. If you don't forward declaration in the implementation files and then you probably do something wrong.

7) [UIWebView] interaction between the UIWebView and the application

http://stackoverflow.com/questions/3738212/getting-objective-c-to-talk-to-javascript-with-uiwebview/3738235# 3738235 writes you can send data from the COCOA layer to the JavaScript layer by using the Stringbyevaluatingjavascriptfromstri Ng:method in UIWebView.
The COCOA layer can also "intercept" link clicks by implementing the Uiwebviewdelegate protocol in your view controller; When a link is clicked, the delegate method WebView:shouldStartLoadWithRequest:navigationType:will being called, at which PO int the COCOA layer can do the kind of "pop-up" action you ' re looking for.
(Although I would ask why do you want to generate pop-ups like this.) My gut feeling tells me, this would look and feel quite annoying from the user's point of view.)

8) [UI] A great article for Popoverview usage

Http://mobiforge.com/designing/story/using-popoverview-ipad-app-development

9) [Design] Minimize asynchronous UI operations because UI operations are non-thread-safe (need to be performed on the main thread). If the interface is more complex, consider using UIWebView

[Tip] Good posts to solve library sharing between multiple Osx/ios projects.

http://zetetic.net/blog/2010/02/15/building-static-libraries-to-share-code-on-iphone-and-mac-os-x-projects/

Code that can be reused between iOS and OSX

The feasibility of writing Android and iOS shared code using C

one) [Tip] IOS weak link frame for multiple SDK compatibility

http://stackoverflow.com/questions/2627797/weak-link-framework/2629693#2629693 wrote you were getting that error because You is building against a version of the SDK that is does not implemement the MESSAGEUI framework.
What are need to does is to build for iphone OS 3.0, but in the build settings for your target set the iphone OS Deployment Target to IPhone OS 2.0 (or whatever minimum version of you "D like to support with your final application). This is the weak-link against the newer framework, but can still deploy the application to older devices.

one) [UI] let UIWebView support gesture

http://justinimhoff.com/swipe-gesture-with-uiwebview/

[UI, Tip] The position of the picture where the text is arranged on the button

set the imageedgeinset   and titleedgeinset   to move the components around within your image .  

http://stackoverflow.com/questions/2515998/iphone-uibutton-image-position/2516108#2516108

[UI layout] A good example of dynamic layout

Three20:ttstyledlayout.m

-(void) Layouttext: (ttstyledtextnode*) textnode container: (ttstyledelement*) Element {

After a while to add ~

[UI TabBar] raisedcentertabbar

http://idevrecipes.com/2010/12/16/raised-center-tab-bar-button/

Https://github.com/boctor/idev-recipes/tree/master/RaisedCenterTabBar

[Error] "wait_fences:failed to receive reply:10004003"?

Change the elements on the view before Viewdidappear

[Grammar] @synthesize and @dynamic

@synthesize'll generate getter and setter methods for your property. @dynamic just tells the compiler that the getter and setter methods is implemented not by the class itself but somewhere Else (like the superclass)

Try to avoid using alloc in Viewdidload to generate new objects, if the person needs to release in Viewdidunload, because the memory warning occurs when viewdidunload is triggered, So viewdidload will be called multiple times .

----Alloc in Viewdidload and then release in Viewdidunload is the correct way to manage memory. In this case, you need to reply to the State of the view in Viewdidload, so you need to use a data model to record the state of the view.

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.