一些IOS开发的心得:
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是个重量级的框架,差不多是自己重新实现了IOS的UI组件, 使用需谨慎!
3) [Design] Single UIViewController or Mutiple UIViewController, need think~
4) [UI] 获取ipad/iphone的当前方向:
Objective c代码class="Apple-converted-space">
5) [Memory Management] Release a variable and set it to nil is a good habit.
Objective c代码
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 和 应用之间的交互
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.
8) [UI] A great article for Popoverview usage
http://mobiforge.com/designing/story/using-popoverview-ipad-app-development
9) [Design] 由于UI操作是非线程安全的(需要在主线程上执行), 尽量减少异步的UI操作. 如果界面比较复杂可以考虑使用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.
11) [UI] 让UIWebView支持Gesture
http://justinimhoff.com/swipe-gesture-with-uiwebview/
12) [UI, Tip] 在按钮上排列文字的图片的位置
Set the monospace, serif; font-size: 14px; vertical-align: baseline; white-space: pre; background-color: #eeeeee;">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] 动态布局的一个很好的例子
Three20: TTStyledLayout.m
- (void)layoutText:(TTStyledTextNode*)textNode container:(TTStyledElement*)element {
以后陆续补充~
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生成新的对象,如果有者需要在viewDidUnload中release;由于memory warning发生时候会触发viewDidUnload,因此viewDidLoad会被多次调用
---- 在viewDidLoad中alloc, 然后在viewDidUnload中release是比较正确的内存管理方式。针对这种情况需要在viewDidLoad中回复view的状态,所以也就需要使用一个数据模型记录view的状态。