国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

IOS開(kāi)發(fā)經(jīng)驗(yàn)分享

2019-11-14 20:13:52
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

一些IOS開(kāi)發(fā)的心得:

 

1) [Multiple Threads] IOS多線程注意, 所有的UI操作都必須在主線程上:

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

示例: [self performSelectorOnMainThread:@selector(updateThumbnail:) withObject:tmpImg waitUntilDone:false];

 

2) [Design] Three20是個(gè)重量級(jí)的框架,差不多是自己重新實(shí)現(xiàn)了IOS的UI組件, 使用需謹(jǐn)慎!

 

3) [Design] Single UIViewController or Mutiple UIViewController, need think~

 

4) [UI] 獲取ipad/iphone的當(dāng)前方向:

Objective c代碼  收藏代碼
  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代碼  收藏代碼
  1. // 在viewDidLoad中alloc或者new的對(duì)象空間需要在這邊釋放  
  2. - (void)viewDidUnload {  
  3.     [_sushiTypes release];  
  4.     _sushiTypes = nil;  
  5. }  
  6.    
  7. - (void)dealloc {  
  8.     [_sushiTypes release];  
  9.     _sushiTypes = nil;  
  10.     [super dealloc];  
  11. }  

 

    http://www.raywenderlich.com/2657/memory-management-in-objective-c-tutorial 寫道

Note that you also set the object to nil afterwards. This is a good PRactice, because by setting it to 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 object your program should crash.

 

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

http://stackoverflow.com/questions/322597/class-vs-import/1350029#1350029 寫道
Three simple rules: * Only #import the super class in header files. * #import all classes you send messages to in implementation. * Forward declarations for everything else. If you do forward declaration in the implementation files, then you probably do something wrong.

 

7) [UIWebView] UIWebView 和 應(yīng)用之間的交互

http://stackoverflow.com/questions/3738212/getting-objective-c-to-talk-to-javascript-with-uiwebview/3738235#3738235 寫道
You can send data from the Cocoa layer to the Javascript layer by using the stringByEvaluatingJavaScriptFromString: 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 be called, at which point the Cocoa layer can do the kind of "pop-up" action you're looking for.
(Although I would ask you why you want to generate pop-ups like this. My gut feeling tells me that this will 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] 由于UI操作是非線程安全的(需要在主線程上執(zhí)行), 盡量減少異步的UI操作. 如果界面比較復(fù)雜可以考慮使用UIWebView

 

10) [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/

ios和osX之間可以重用的代碼

使用c編寫Android和IOS共享代碼的可行性

 

11) [Tip] IOS weak link frame for multiple sdk compatibility

 

http://stackoverflow.com/questions/2627797/weak-link-framework/2629693#2629693 寫道
You are getting that error because you are building against a version of the SDK that does not implemement the MessageUI framework.
What you need to do 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 you'd like to support with your final application). This way, you weak-link against the newer framework, but can still deploy the application to older devices.

 

11) [UI] 讓UIWebView支持Gesture

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

 

12) [UI, Tip] 在按鈕上排列文字的圖片的位置 

Set the imageEdgeInset  and titleEdgeInset  to move the components around within your image. 

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

 

13) [UI Layout] 動(dòng)態(tài)布局的一個(gè)很好的例子

Three20: TTStyledLayout.m

- (void)layoutText:(TTStyledTextNode*)textNode container:(TTStyledElement*)element {

以后陸續(xù)補(bǔ)充~

 

14) [UI TabBar] RaisedCenterTabBar

 

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

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

 

15) [Error] “wait_fences: failed to receive reply: 10004003”?

在viewDidAppear之前改變view上的元素

 

16) [Grammar] @synthesize and @dynamic

 

 

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

 

17) 盡量避免在viewDidLoad中使用alloc生成新的對(duì)象,如果有者需要在viewDidUnload中release;由于memory warning發(fā)生時(shí)候會(huì)觸發(fā)viewDidUnload,因此viewDidLoad會(huì)被多次調(diào)用

---- 在viewDidLoad中alloc, 然后在viewDidUnload中release是比較正確的內(nèi)存管理方式。針對(duì)這種情況需要在viewDidLoad中回復(fù)view的狀態(tài),所以也就需要使用一個(gè)數(shù)據(jù)模型記錄view的狀態(tài)。


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 临猗县| 石林| 且末县| 尤溪县| 六盘水市| 宁都县| 旺苍县| 龙门县| 遂平县| 旅游| 姜堰市| 延吉市| 清原| 名山县| 五常市| 开封县| 河西区| 合肥市| 博罗县| 柘荣县| 九寨沟县| 思茅市| 钟山县| 昂仁县| 阿拉善盟| 措美县| 双鸭山市| 托克托县| 莒南县| 同江市| 保山市| 洪泽县| 辉南县| 通海县| 巴彦淖尔市| 万源市| 蒙自县| 巩义市| 连江县| 伊金霍洛旗| 绍兴市|