IOS programming traps.

Source: Internet
Author: User

Written by: fail programmers-eight gods

    •  Note the unsupported features

For example, if your handheld device does not support sending text messages or emails, nil will be returned when you create this type of category ..., this is different from our usual habitual understanding. If it is my design, it may be better to let it throw an exception. At least we don't need to check the api documentation to know what is going on.

    •  Device direction

When you add two view controllers in the Landscape mode consecutively on the window, the orientation of the second view will remain in portrait mode, and its shouldAutorrotateToInterfaceOrientation method will not be triggered...

    •  Output port in the Root View

This is not counted. It can be determined based on the developer's personal understanding. According to the traditional programming idea, when a View Controller is instantiated from the nib file, I think all the output control controls in the view will be automatically initialized, but Apple's mode is not. It needs to stimulate the view attribute of the Root view and confirm that all the following subviews are connected to the output port.

    •  Play an animation before busy work begins.

This is another apple mode. If you want to play the waiting animation while downloading the file, if you want to execute the code first (note that the code is executed directly instead of delayed execution, the previous animation will be played after busy code execution, obviously not what we need.

[activityIndicator startAnimating];[self performSelector:@selector(someMethod) withObject:nil afterDelay:0.0];

This is Apple's Q & A about screen rotation. It also says that window only supports rotation of the first view ....
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 essential 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 shocould 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 wowould 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 shoshould 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/>

 

There is no problem with the display delay of uiimageview and button images in the custom table.

However, the uiimageview display may fail. If you are in a local file, the display success rate will be high. If you are using an online image, it will not be displayed.

On May 25, the reason was found: the custom property self. imageView has the same name as the system property, and it is normal to change the name to a sub-account .....

[Self setNeedsLayout] leads to the final image view. When asynchronous loading is complete, it comes to the front, that is, its z-index has changed, the result blocks other label views...
# 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) upd AteCellContent :( 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? //});}];

 

 

Related Article

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.