作者:不及格的程式員-八神
比如你的手持功能不支援傳送簡訊或郵件的話,建立該類型的類時將返回nil...,這與我們平常習慣性的理解不同,如果是我設計我會讓它拋出異常可能會更好,至少不需要查api文檔就知道怎麼回事。
當你在window上連續添加兩個景色模式的視圖控制器的時候,第二個視圖的方向會保持人像模式,並且它的shouldAutorrotateToInterfaceOrientation方法不會被觸發...
這個算不算,可以根據開發人員的個人理解而定,按傳統編程想法,當從nib檔案執行個體化一個視圖控制器時,我覺得視圖中的所有輸出口控制項都會自動初始化,但是蘋果的模式不是,它需要激髮根視圖view屬性,確認將下面的所有子視圖串連到輸出口上.
這又是一個蘋果模式,如果你想在下載檔案的時候同時播放等待動畫,如果你先去執行(注意是直接執行而不是延時執行)下載代碼,那麼前面的動畫將在煩忙的代碼執行完畢後播放,顯然不是我們要的.
[activityIndicator startAnimating];[self performSelector:@selector(someMethod) withObject:nil afterDelay:0.0];
這是蘋果關於旋轉螢幕問題的答QA,裡面也說了window僅支援第一個視圖的旋轉....
Technical Q&A QA1688<br />Why won't my UIViewController rotate with the device?</p><p>Q: Why won't my UIViewController rotate with the device?</p><p>A: Why won't my UIViewController rotate with the device?</p><p>There can be several possible reasons your view controller does not rotate.</p><p>The UIViewController class provides the fundamental view-management model for iPhone applications. It provides automatic support for rotating the views of the view controller in response to changes to the orientation of the device. If the autoresizing properties of your view and subviews are properly configured, this behavior is essentially free. Your view controller may not rotate in certain situations if:</p><p>The view controller does not implement this delegate method:<br />- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;</p><p>Even if shouldAutorotateToInterfaceOrientation is implemented, you should make sure it returns YES for all the orientations you wish to support. To support all orientations, simply always return YES.</p><p>The view controller's UIView property is embedded inside UIWindow but alongside an additional view controller.<br />You may find a situation where shouldAutorotateToInterfaceOrientation is called once at startup for a given view controller but is never called again when the device is rotated. Because view controllers are tightly bound to the views they manage, they are also part of the responder chain used to handle events. View controllers are themselves descendants of the UIResponder class and are inserted into the responder chain between the managed view and its superview. So it is common practice to have one primary view controller in your application as part of the responder chain. You would typically add one primary view controller such as a UINavigationController, UITabBarController or a generic UIViewController to your UIWindow. For example, this is done by calling:</p><p>[myWindow addSubview:primaryViewController.view];</p><p>If you add an additional view controller's UIView property to UIWindow (at the same level as your primary view controller) via the following:</p><p>[myWindow addSubview:anotherController.view];</p><p>this additional view controller will not receive rotation events and will never rotate. Only the first view controller added to UIWindow will rotate.</p><p>Note: You may add one view controller's UIView property as a subview to another view controller. In doing so, both views will rotate but the parent view controller remains in charge of determining the supported orientations via its shouldAutorotateToInterfaceOrientation method.<br />Note: Keep in mind that UINavigationController and UITabBarController have the capability to manage a "stack" or "list" of view controllers on their own.<br />You have added your view controller's UIView property to UIWindow as a subview, but prematurely released it soon after.<br />UIWindow will retain that view, but not the view controller itself. You must not release it prematurely. Declare it as a "retainable" property in your UIApplicationDelegate subclass.</p><p>Note: UINavigationController and UITabBarController retain your view controllers, so you can release them once they have been added.<br />All child view controllers in your UITabBarController or UINavigationController do not agree on a common orientation set.<br />To make sure that all your child view controllers rotate correctly, you must implement shouldAutorotateToInterfaceOrientation for each view controller representing each tab or navigation level. Each must agree on the same orientation for that rotate to occur. That is, they all should return YES for the same orientation positions.</p><p>Overriding the -(id)init: or -(id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle method without calling super. For the object to be initialized properly, you must call super on any init or initWithNibName method you are overriding for your view controllers.<br />
自訂表格格中的uiimageview與button圖片的延遲顯示問題,button沒有問題。
但uiimageview顯示會出現問題,如果你在本地檔案,顯示成功率會大,如果是網上的圖片,就不會顯示了。
2013-06-25日找到原因:自訂屬性self.imageView 與系統屬性同名了,改個名子 就都正常了。。。。。
[self setNeedsLayout] 導致了最後面的圖片視圖,在非同步載入完成時,跑來了最前面,就是說它的z-index改變了,結果會把其它的標籤視圖擋住。。。
#import "InfoListTableCell.h"#import "InfoListEntity.h"@implementation InfoListTableCell- (id)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) { // Initialization code } return self;}/*// Only override drawRect: if you perform custom drawing.// An empty implementation adversely affects performance during animation.- (void)drawRect:(CGRect)rect{ // Drawing code}*/-(void)updateCellContent:(id)obj{ InfoListEntity *entity = (InfoListEntity*)obj; self.ownEntity = entity; self.labTitle.text = entity.title; [entity.imageURL getCacheDataDir:@"cacheDir" completionHandler:^(NSData *data, NSError *error) { //dispatch_async(dispatch_get_main_queue(), ^ //{ self.imageView.image = [UIImage imageWithData:data]; [self setNeedsLayout]; 如果是網上下載,這句非常重要,有本機快取就不需要,為什嗎? //}); }];