Java to ios-problems and solutions

Source: Internet
Author: User

Encountering Problems and Solutions

? ? This article is a summary of the first project in Java to ios-, analysis of some problems encountered and solutions, share some of the harvest.

1.UITableView Sliding lag optimization

?? Because UITableView there are many pictures in the cell, on the 4/4s on the sliding comparison card, the first thought is the machine is too old, but the contrast and QQ space, found still our problem, so the latter is optimized, through Xcode performance monitoring, memory changes are not small, but the CPU soared two bad, The Product-profile-time profiler was monitored through Xcode's Time Profiler tool and found a slow way to perform, because the path of the image was converted by calling its own method for log printing, causing slippage.

? ? Online about UITableView The performance optimization of the article there are many, the official gave an example lazytableimages introduction lazy loading image UITableview , when sliding, do not load the picture, stop sliding when loading the picture, and put UIImage in the object, The image in the judging object is not empty and the picture is displayed, or the bitmap is still occupied. Examples of pictures are the app's icon, are small pictures, so it is no problem. But the picture in our project is a big picture, if the picture is placed in the object, obviously not suitable, so then pass this scheme.

? ? A few days ago in the Glow Technical team blog saw Uiscrollview practical experience
This blog, the inside of the same technology, optimized the sliding deceleration process also carries on the picture loading, in addition uses the sdwebimage, inside to judge whether Sdwebimage has cached the picture, if caches, loads the picture from the local, otherwise uses occupies the bitmap, should be the better solution

2. Right swipe gesture back

? ? IOS7 comes with this feature, and then the designers put forward the optimization suggestions, but our program does not support this function, because the method of return operation of the program contains other business logic, such as the return to refresh the previous page of data, return to show whether the bottom menu. And the system's default right-slip return, just do the page return, and will not trigger its own return method.

? ? So in order to this function or the code has been modified to update the upper page of the operation of the page in the data refresh place. The bottom menu is hidden only on several pages of the home page, and other related business logic is removed. Because the change to this place is also a conflict with the test, because the project is nearing the end, modification may cause problems, the optimized function can be placed in the late. However, as a developer, the changes were made and overtime was tested. On the surface this is an optimization, in fact, it is a problem leak. If there are new needs can not be done, but the problem should be resolved as soon as possible.

? ? In addition to this place to do a content supplement, the reverse data transfer between pages, can be used callback (block), delegation (delegate) and notification (notifacation), need to master these points of knowledge and implementation methods, distinguish between the differences.

3. Add Page Stats

? ? Friends of the league statistics is relatively strong, although the project does not require adding related functions, but still add the relevant statistics, need to add a line of code in the corresponding Viewcontroller, the name of the viewWillAppear viewWillDisappear current page, the first only added a few pages, so the code is written dead. All pages to add statistics, the code needs to be improved, encapsulated in their own baseviewcontroller

-(void)beginLogPageView{    [MobClick beginLogPageView:NSStringFromClass([self class])];}-(void)endLogPageView;{    [MobClick endLogPageView:NSStringFromClass([self class])];}

? ? It's easier to call statistics on a sub-page.

-(void)viewWillAppear:(BOOL)animated{    [super viewWillAppear:animated];    //添加页面统计    [self beginLogPageView];}-(void)viewWillDisappear:(BOOL)animated{    [super viewWillDisappear:animated];    //结束页面统计    [self endLogPageView];}

? ? Method swizzling and AOP practice provide a larger solution, and by the way you can learn the OC runtime.
?? In the Java World, the spring framework is known for IOC and AOP, so the language and the involved are all figured out. Although as an IO is a novice, but I understand the AOP _.

Version 4.debug and release

? ? Before themselves for the debug version and release version of not too many concepts, just know the development of the time is the debug version, when the release of the time to change into a release version, see some macro definition, according to different versions of different macros, such as debug the version of the time, NSLog you can output, release When not output.

? ? Some time ago, see a Xcode macro definition options and release version to NSLog article, just want to understand, in Xcode can set the macro, debug there is a default setting debug=1, so

#if DEBUG    #warning NSLogs will be shown#else#define NSLog(...) {}#endif

Should be judging the value.
? ? In the previous Javaweb project, we will use the Maven project management, in Maven the pom.xml can add profiles, configure different versions, such as the development version, beta, production version, different versions have different configuration files, such as database connection, log configuration, etc. You can compile the project by Maven selecting a different version when you package it. The benefit is that when switching versions, there is no need to modify the associated strip code to avoid unnecessary errors.

? ? After going to iOS has been looking for the relevant solution, and later realized that this can be done, but only in the Apple version debug and release version, there is no way to customize the new version (or I have not found, please God enlighten), but can also be configured to ensure that release the configuration is correct

In addition, the repeated reference to the header file in C/C + + error, so the header file reference can use the following method, the custom header file reference name, Xcode generated the header file will be added by default this

#ifndef xxxx#define xxxx#endif

So it will cause a doubt, oneself usually in the program if not the reference header file, whether it will cause conflict, online search to give the answer. The reference header file is not recommended in OC #include , it #import is recommended to solve this problem.

5. About page Refresh

? ? A page, may include a drop-down refresh, pull-up loading more, page to the end of the hidden refresh, no Network load data from the cache, etc., so the function of the page refresh is best to consider in advance, otherwise these features in the late modification will become cumbersome, accidentally prone to problems. For example, page to last hide load more, and then drop the refresh, you may need to show the hidden control. So the code should be considered well, well designed, packaged well.

6. About page layouts

? ? Most of the current iOS tutorials speak of storyboards, but in real projects, more code is used.
Tang Qiao's blog storyboard– looks very beautiful
Explained the reason, the company project is a collaborative development, once two people at the same time modify the storyboard, basically will have a conflict, it will be very troublesome to solve, so as a novice or should learn more pure code development. The previous project used the code-writing UI to get a wide screen, calculate coordinates between different controls, and if the code was not canonical, the coordinates and the height of the control were independent, and an avalanche would occur if a control changed.

? ? The recommended masonry, also known as an iOS component on GitHub, addresses the cumbersome and tedious drawbacks of automatic layout writing constraints, and is easier to learn and accept. iOS also has a VFL language that feels better compared to masonry.

? ? Another iOS component is recommended here, Reactivecocoa, is a KVO component, used to do message monitoring, the effect is to write the same as the Java event listener write OC code. Before giving a UIButton binding event, you need to call the addtarget binding, and then write a method, or listen to UITextFiled the changes, have to write a lot of delegate methods. After using Reactivecocoa, the writing is changed greatly, the code will look neat and tidy, and appear relatively tall.

? ? Now that the new project is added, the above two components are used.

7. Recommended Blogs

Tang Qiao Technical Blog, the earliest because do not know Tang Qi was despised by colleagues, from his blog can see the changes in iOS, the author is also from Java to iOS, blog is also easy to understand, now Bo master himself although not blogging, but will send weekly share more good blog and open source projects

Glow Technical Team Blog, although there are several blog posts, but are more useful, but also belong to the Advanced promotion type

Java to ios-problems and solutions

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.