IOS work encounters a problem record

Source: Internet
Author: User

1, the scrolldelegate problem of UITableView

Afternoon encountered a strange problem, have not noticed before, because a VC to achieve TableView and other view location linkage,
So realized the TableView delegate in the Scrollviewdidscroll method, the results in click on the product push product Details VC B, the problem arises.

Problem performance:
In the call [Self.navigationcontroller PUSHVIEWCONTROLLER:PRODUCTDETAILVC Animated:yes];
The TableView in VC a always scrolls to the top (Contentoffset has been modified)

See for a long time also did not find the problem, behind in scrollviewdidscroll position added a breakpoint, found in Navigationcontroller in the process of push VC B, the system will call a VC A in the TableView Scrollviewdidscroll method, the key is that the incoming contentoffset in the call is problematic (0,-CONTENTINSET.Y), so that the TableView in VC a will automatically return to the head

Solution: In VC a viewwilldisappear when set TableView delegate for nil, at the same time in the Viewwillappear TableView of delegate set back, the problem is resolved out.
All on all the problem is strange, I hope you no longer be troubled by the same problem

2. The Exclusivetouch attribute of UIView

By setting [selfsetexclusivetouch:YES], you can achieve exclusivity when multiple controls on the same interface accept events, thus avoiding some problems.

3, Uiscrollview and UITableView nested when click Statusbar,scrollview not back to the problem

Apple's comments on the Uiscrollview header file can clearly solve our confusion

When the user taps the status bar, the scroll view beneath the touch which are closest to the status bar would be Scrolle D to top, if it's ' Scrollstotop ' property is YES, it delegate does not return No. from ' Shouldscrollviewscrolltoto P ', and it isn't already at the top.

On the IPhone, we execute this gesture only if there's one on-screen scroll view with ' scrollstotop ' = = YES. If more than one is found, none would be scrolled.

@property(nonatomic) BOOL scrollstotop; //default is YES.

4. JSON Kit Data Conversion problem

JSON is a very common network packet format, and JSON is often used to transfer data between the client and the server. For some dictionary types of data, if an item is empty, it will be passed ' <null> ', and the Jsonkit conversion will produce a corresponding [NSNull null] object, which is not very safe for iOS. For example, a contract for a good item is a string type, the result JSON kit is converted to [NSNull NULL], this time if it is not judged as a nsstring processing there will be problems. Therefore, it is more secure to convert this data type directly to nil, and the conversion method is as follows:

#define PASS_NULL_TO_NIL (instance) (([Instance Iskindofclass:[nsnull class])? nil:instance)

It is basically safe to call any method against nil.

5, IOS 7 system custom VC Right slide return feature does not take effect

IOS 7 starts with a new Uinavigationcontroller in the VC hierarchy and returns to the top-level feature, which is turned on by default. However, in the project there is a custom VC in this feature is invalid, troubleshooting half a day to locate the problem as follows:

Self.navigationItem.leftBarButtonItem = [[Uibarbuttonitem alloc] initwithimage:[uiimage imagenamed:@ "Navigation_bar _back.png "]  style:uibarbuttonitemstyleplain                                                                        target:self                                                                        Action: @selector (backaction:)];  

There's nothing wrong with this piece of code, just a simple custom back button. But the problem is here, as long as the custom Leftitem right slide back to the previous level will be effective.

Because I this VC in the UI is more complex, scrollview,tableview a variety of nesting, so at first also suspected is not a gesture conflict caused, and later found that the right to return the property has nothing to do with the gesture we can touch. The problem is solved by modifying the above code to the following code.

if (is_ios_6) {        Self.navigationItem.leftBarButtonItem = [[Uibarbuttonitem alloc] Initwithimage:[uiimage imagenamed:@ "Navigation_bar_back.png"]                                                                                 style:uibarbuttonitemstyleplain                                                                                target:self                                                                                action:@ Selector (backaction:)];}

Only for system custom back buttons prior to iOS 7, iOS 7 and later directly use the system's return icon "<".

We can also directly get this gesture "interactivepopgesturerecognizer" and do some custom action.

For more detailed information, refer to: http://www.cnblogs.com/lexingyu/p/3432444.html

6, UITableViewCell Check to keep the problem

The selected state of the cell in the UITableView cannot be persisted after calling Reloaddata, so I try to restore the selected state in the Cellforrowatindexpath in order to keep it active, the code is as follows:

-(uitableviewcell*) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{    static NSString *cellidentifier = @ "Myaccountmenucellidentifier";    UITableView *cell = [TableView dequeuereusablecellwithidentifier:cellidentifier];    if (!cell) {        cell = [[UITableViewCell alloc] Initwithstyle:uitableviewcellstyledefault                                      reuseidentifier: Cellidentifier];    }       ...        Restore checked    if (_currentselectedindexpath        && indexpath.row = = _currentselectedindexpath.row        & & indexpath.section = = _currentselectedindexpath.section) {        [cell setselected:yes animated:no];    }    else {        [cell setselected:no animated:no];    }    return cell;}

The discovery does not work at all and also attempts to reload the custom cell's

-(void) setselected: (BOOL) selected animated: (bool) animated;-(void) sethighlighted: (BOOL) highlighted animated: (bool ) animated;

There was also no progress, and finally finally passed the overloaded Reloaddata, code as follows:

-(void) reinvokecurrentmenuitem{    [self selectrowatindexpath:_currentselectedindexpath                      animated:no                Scrollposition:uitableviewscrollpositionnone];        [Self tableview:self didselectrowatindexpath:_currentselectedindexpath];}

That is, after each reload to do a selectrowatindexpath operation to restore the selected. Although the problem is solved, but this method also has the potential risk, such as the reload process of the data source changes, may be selected before the cell Indexpath has changed, light is selected the incorrect cell, serious if the number of cells after the refresh is reduced, Passing in an oversized indexpath will cause a crash.

So this method, please June "and cherish".

7, Uitextfield when the Textfielddidbeginediting method is implemented, CLEARBTN does not respond because the simplest view overlay causes the event to be intercepted.

If you must implement delegate, you can use the way you set Rightview

This question I finally solved, said all embarrassed, was covered by other view, so out of the problem still have to think about is not their own problems.

In the process of checking this problem, I found a very useful gdb debugging method, directly in GDB input the following command to print the current app's view level.

I know there is a charge tool on the internet called reveal, can be more dazzling view level, the good news is that XCode6 debug comes with the ability to see the view level. The underlying implementation mechanism is the same, the individual paranoid feel or command line printing more clearly, especially when the view level is many.

8, block is empty is called will crush

Yesterday encountered a crash problem, checked the discovery is the block is nil, then I called the block, the program crash. I started to wonder if it was me. Block is caused by the Dispatch_async crash, the subsequent test found that as long as the block is nil, call this block will crash.

A simple example is as follows:

Defines a block type typedef void (^completeblock) ();    Declares a variable of type Completeblock completeblock Cblock = Nil;cblock ();       The call will be Crashdispatch_async (Dispatch_get_main_queue (), ^{    cblock ();   Call will also be crash});

Define a nil block, no matter how the call will be crash, do not know why Apple did not protect, in short, after the call block before the first to judge the more reliable.

9, Uiimagepickercontroller black screen problem

When using Uiimagepickercontroller to complete the photo selection, it is found that the black screen on the iOS8, the other devices are normal. Checked for a while to find the original test in the system settings to the app camera permissions closed, the test did not notice this. We always thought that this is the iOS 8beta version of the bug, looking for a long time to find the original reason is very simple. Anyway, since iOS7 after the user can control the camera permissions, then our app can do better, more friendly, so check the data found that the Avfoundation library provides the API to detect camera authorization status, so there is the following function.

Takephoto

The code shows whether the detection system supports taking pictures, and then detects if the app has permission to take a photo, and finally enters the photo screen, prevents the simulator from debugging when it is crash, or when the camera screen is turned off when the real Machine Debug permission is closed.

10, XCode archive out of the package in the local organizer see the app no icon problem

The appearance of xcassets greatly facilitates us to provide the corresponding icon in the app, so we can no longer worry about the various names of icon, such as icon-57.png and so on. I've also had a problem with the app being rejected because it didn't provide a complete icon, and now these problems are basically nonexistent.

Yesterday in the archive package to see the local organizer display of the ipad incredibly no icon, repeatedly check xcassets, found that all icons have, there should be no problem ah. Later find data found this may be a bug in Xcode, the local display no icon, but installed on the device level submitted to the AppStore and then downloaded are icons, does not affect the audit and use, is purely display problems.

How to solve this problem, check the app in the Xxx-info.plist file, add the icon file property, and fill in the non-Retian and Retian screen corresponding icon name (the file must exist, and named as follows), as shown in:

Once again archive can be found, the local Organizerz app has icon.

IOS work encounters a problem record

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.