< turn >java ios-First project Summary (2): Problems encountered and solutions

Source: Internet
Author: User

Directory
1.UITableView Sliding lag optimization

2. Right swipe gesture back

3. Add Page Stats

Version 4.debug and release

5. About page Refresh

6. About page layouts

7. Recommended Blogs

Encountering Problems and Solutions

This article is a summary of the first project in Java ios-(1), the content of the analysis encountered some problems and solutions, share some of the harvest.

1.UITableView Sliding lag optimization

Because the ' UITableView ' cell has a lot of pictures in the 4/4s on the sliding comparison card, the first thought is the machine is too old, but the contrast and QQ space, the discovery is still our problem, so the later optimization, through Xcode performance monitoring, memory changes are not small, But the CPU soared two powerful, through the Xcode Time Profiler tool to monitor (Product-profile-time Profiler), found a slow way to perform, because when the image path conversion, call their own method of log printing , causing a sliding lag.

Online about UITableView performance optimization of the article there are many, the official gave an example lazytableimages introduced lazy loading uitableview image, when sliding, do not load the picture, stop sliding when loading the picture, And put the uiimage in the object, judging the object in the picture will not empty display the picture, or the bitmap. 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, you can use 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 still relatively strong, although the project does not require the addition of related functions, but still add the relevant statistics, need in the corresponding viewcontroller in the Viewwillappear and viewwilldisappear to add a line of code, the name of the current page, Only a few pages were added at the beginning, so the code was written dead. All pages to add statistics, the code needs to be improved, encapsulated in their own baseviewcontroller

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

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

12345678910 -(void)viewWillAppear:(BOOL)animated{    [superviewWillAppear:animated];    //添加页面统计    [self beginLogPageView];}-(void)viewWillDisappear:(BOOL)animated{    [superviewWillDisappear: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 myself for the debug version and release version does not have too many concepts, just know the usual development of the time is the debug version, when the release to the release version, see some macro definition, according to different versions of the macro settings, such as Debug version, NSLog can output, When release is 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 macros, debug has a default setting debug=1, so

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

Should be judging the value.

In the previous Javaweb project, we will use MAVEN for project management, in Maven 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 choose a different version from Maven when compiling your project. 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 Debug version and release version, there is no way to customize the new version (or I have not found, please God enlighten), but can also be related to the configuration, Ensure that the release version is configured correctly

In addition, the repeated reference to the header file is error in C + +, 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

123 #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 # include reference header file is not recommended in OC and the recommended use of #import is 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 Blog storyboard– looks very beautiful explained the reason, the company project is a collaborative development, once two people at the same time modified the story board, basically will have a conflict, solve it will be very troublesome, so as a novice or should learn the 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.

Here is another iOS component--reactivecocoa, is a KVO component, used to do message monitoring, the effect is to be like Java write event listening to 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 changes, and write many 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 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.

< turn >java ios-First project Summary (2): Problems encountered and solutions

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.