Questions about iOS development (7)

Source: Internet
Author: User
How can I make the size of UIWebView conform to the HTML content? In iOS5, this is very simple. set the webview delegate and then implement didFinishLoad in the delegate: Method: 71. how can I make the size of UIWebView conform to the HTML content?
In iOS5, this is very simple. set the webview delegate and then implement didFinishLoad in the delegate: method:

-(void)webViewDidFinishLoad:(UIWebView*)webView{CGSizesize=webView.scrollView.contentSize;//iOS5+webView.bounds=CGRectMake(0,0,size.width,size.height);}

72. how to quickly release the keyboard with multiple Responder in the window
[[UIApplicationsharedApplication] sendAction: @ selector (resignFirstResponder) to: nilfrom: nilforEvent: nil];
In this way, the focus of all responders can be lost at one time.
73. how can I enable UIWebView to scale through the "kneading" gesture?
Use the following code:

webview=[[UIWebViewalloc]init];webview.autoresizingMask=(UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight);webview.scalesPageToFit=YES;webview.multipleTouchEnabled=YES;webview.userInteractionEnabled=YES;

74. Undefinedsymbols: _ kCGImageSourceShouldCache, _ CGImageSourceCreateWithData, _ CGImageSourceCreateImageAtIndex

ImageIO. framework is not imported.

75. expectedmethodtoreaddictionaryelementnotfoundonobjectoftypensdictionary

SDK6.0 adds a "subscript" Index to the dictionary, that is, the dictionary objects are retrieved using the dictionary [@ "key"] method. However, this is invalid in SDK5.0. You can create a new head file NSObject + subscripts. h in the project to solve this problem. The content is as follows:

#if__IPHONE_OS_VERSION_MAX_ALLOWED<60000@interfaceNSDictionary(subscripts)-(id)objectForKeyedSubscript:(id)key;@end@interfaceNSMutableDictionary(subscripts)-(void)setObject:(id)objforKeyedSubscript:(id
 
  )key;@end@interfaceNSArray(subscripts)-(id)objectAtIndexedSubscript:(NSUInteger)idx;@end@interfaceNSMutableArray(subscripts)-(void)setObject:(id)objatIndexedSubscript:(NSUInteger)idx;@end#endif
 

76. Error:-[MKNetworkEnginefreezeOperations]: messagesenttodeallocatedinstance0x1efd4750
This is a memory management error. The MKNetwork framework supports ARC and should not have memory management problems. However, due to some bugs in the MKNetwork, this problem occurs when the MKNetworkEngine is not set to the strong attribute. We recommend that you set the MKNetworkEngine object to the strong attribute of ViewController.

77. differences between UIImagePickerControllerSourceTypeSavedPhotosAlbum and UIImagePickerControllerSourceTypePhotoLibrary
UIImagePickerControllerSourceTypePhotoLibrary indicates the entire photo library, allowing users to select all albums (including camera films), while UIImagePickerControllerSourceTypeSavedPhotosAlbum only includes the camera film.
78. warning "Prototypetablecellsmusthaveresueidentifiers"
The Identidfier attribute of Prototypecell (iOS5 template cell) is not filled in. enter it in the attribute template.
79. how do I read the value in info. plist?
The following sample code reads URLSchemes from info. plist:

//TheInfo.plistisconsideredthemainBundle.mainBundle=[NSBundlemainBundle];NSArray*types=[mainBundleobjectForInfoDictionaryKey:@"CFBundleURLTypes"];NSDictionary*dictionary=[typesobjectAtIndex:0];NSArray*schemes=[dictionaryobjectForKey:@"CFBundleURLSchemes"];NSLog(@"%@",[schemesobjectAtIndex:0]);

80. how can I disable automatic disbanding of the AtionSheet?
UIActionSheet is automatically disbanded no matter what button you click. The best way is to subclass It. add a noAutoDismiss attribute and overwrite the dismissWithClickedButtonIndex method. if this attribute is YES, the disband action is not performed. if it is NO, the default dismissWithClickedButtonIndex is called:

#import
 
  @interfaceMyAlertView:UIAlertView@property(nonatomic,assign)BOOLnoAutoDismiss;@end#import"MyAlertView.h"@implementationMyAlertView-(void)dismissWithClickedButtonIndex:(NSInteger)buttonIndexanimated:(BOOL)animated{if(self.noAutoDismiss)return;[superdismissWithClickedButtonIndex:buttonIndexanimated:animated];}@end
 

81. crash when executing the RSA_public_encrypt function
This is a strange problem. Two devices are used. one system is 6.1 and the other is 6.02. the same code works normally in version 6.02, causing program crash in version 6.1:

unsignedcharbuff[2560]={0};intbuffSize=0;buffSize=RSA_public_encrypt(strlen(cleartext),(unsignedchar*)cleartext,buff,rsa,padding);

The problem is that:

buffSize=RSA_public_encrypt(strlen(cleartext),(unsignedchar*)cleartext,buff,rsa,padding);

In the 6.1 system, the iPad is a 3G version. due to the unstable signal of the 3G network (Unicom 3 gnet) used, the rsa public key is often unavailable, so the rsa parameter appears nil. In the 6.0 system, the iPad is a Wi-Fi version, and the signal is stable. The solution is to check the validity of the rsa parameter.
82. WARNING: UITextAlignmentCenterisdeprecatediniOS6
NSTextAlignmentCenter has been replaced by UITextAlignmentCenter. There are also some alternatives, you can use the following macros:

#ifdef__IPHONE_6_0//iOS6andlater#defineUITextAlignmentCenter(UITextAlignment)NSTextAlignmentCenter#defineUITextAlignmentLeft(UITextAlignment)NSTextAlignmentLeft#defineUITextAlignmentRight(UITextAlignment)NSTextAlignmentRight#defineUILineBreakModeTailTruncation(UILineBreakMode)NSLineBreakByTruncatingTail#defineUILineBreakModeMiddleTruncation(UILineBreakMode)NSLineBreakByTruncatingMiddle#endif

83. unable to set-fno-objc-arc in Xcode5
Xcode5 uses ARC by default and hides the "CompilerFlags" column in CompileSources. Therefore, you cannot set the-fno-objc-arc option of the. m file. To display. for the CompilerFlags column of the m file, you can use the menu "View-> Utilities-> HideUtilities" to temporarily close the Utilities window on the right to display the CompilerFlags column, so that you can set it. the-fno-objc-arc flag of the m file.
84. WARNING: 'abaddressbookcreate 'isdeprecated: firstdeprecatediniOS6.0
This method is discarded after iOS6.0 and replaced by the abaddressbookcreatewitexceptions method:

CFErrorRef*error=nil;ABAddressBookRefaddressBook=ABAddressBookCreateWithOptions(NULL,error);

85. how do I read the mobile phone address book after iOS6.0?
After iOS6, the AddressBook framework has changed, especially when the app accesses the mobile phone address book, it needs to be authorized by the user. Therefore, in addition to the new abaddressbookcreatewitexceptions initialization method, we also need to use the new ABAddressBookRequestAccessWithCompletion method of the AddressBook framework to determine whether the user is authorized:

+(void)fetchContacts:(void(^)(NSArray*contacts))successfailure:(void(^)(NSError*error))failure{#ifdef__IPHONE_6_0if(ABAddressBookRequestAccessWithCompletion){CFErrorReferr;ABAddressBookRefaddressBook=ABAddressBookCreateWithOptions(NULL,&err);ABAddressBookRequestAccessWithCompletion(addressBook,^(boolgranted,CFErrorReferror){//ABAddressBookdoesn'tgauranteeexecutionofthisblockonmainthread,butwewantourcallbackstobedispatch_async(dispatch_get_main_queue(),^{if(!granted){failure((__bridgeNSError*)error);}else{readAddressBookContacts(addressBook,success);}CFRelease(addressBook);});});}#else//oniOS<6ABAddressBookRefaddressBook=ABAddressBookCreate();readAddressBookContacts(addressBook,success);CFRelease(addressBook);}#endif}

This method has two block parameters: success and failure, which are used to execute user-authorized access.
When the code calls the ABAddressBookRequestAccessWithCompletion function, the first parameter is a block. the granted parameter of this block is used to inform the user whether to agree. If granted is No, we call the failure block. If granted is Yes, we will call the readAddressBookContacts function to further read the contact information.
The readAddressBookContacts statement is as follows:

staticvoidreadAddressBookContacts(ABAddressBookRefaddressBook,void(^completion)(NSArray*contacts)){//dostuffwithaddressBookNSArray*contacts=(NSArray*)CFBridgingRelease(ABAddressBookCopyArrayOfAllPeople(addressBook));completion(contacts);}

Obtain all contacts from addressBook (put the results in an NSArray array), and then call the completion block (success block of the fetchContacts method ). In completion, we can iterate the array.
An example of calling the fetchContacts method:

+(void)getAddressBook:(void(^)(NSArray*))completion{[selffetchContacts:^(NSArray*contacts){NSArray*sortedArray=[contactssortedArrayUsingComparator:^(ida,idb){NSString*fullName1=(NSString*)CFBridgingRelease(ABRecordCopyCompositeName((__bridgeABRecordRef)(a)));NSString*fullName2=(NSString*)CFBridgingRelease(ABRecordCopyCompositeName((__bridgeABRecordRef)(b)));intlen=[fullName1length]>[fullName2length]?[fullName2length]:[fullName1length];NSLocale*local=[[NSLocalealloc]initWithLocaleIdentifier:@"zh_hans"];return[fullName1compare:fullName2options:NSCaseInsensitiveSearchrange:NSMakeRange(0,len)locale:local];}];completion(sortedArray);}failure:^(NSError*error){DLog(@"%@",error);}];}

That is, the contact names are sorted in Chinese in the completion block of fetchContacts. Finally, the completion block is called. In the error block of fetchContacts, the error message is printed.
The sample code for calling getAddressBook is as follows:

[AddressBookHelpergetAddressBook:^(NSArray*node){NSLog(@"%@",NSArray);}];

86. ARC warning: PerformSelectormaycausealeakbecauseitsselectorisunknown
This is a specific warning in ARC. simply ignore it with the # pragmaclangdiagnostic macro:

#pragmaclangdiagnosticpush#pragmaclangdiagnosticignored"-Warc-performSelector-leaks"[targetperformSelector:selwithObject:[NSNumbernumberWithBool:YES]];#pragmaclangdiagnosticpop

87. 'libxml/HTMLparser. h' filenotfound
This error occurs after libxml2.dylib is imported, especially when the ASIHTTP framework is used. Add "$ {SDK_DIR}/usr/include/libxml2" to the HeaderSearchPaths list of BuildSettings to solve this problem.
The so-called "$ (SDK_ROOT)" refers to the Directory of the SDK used for compiling the target. taking iPhoneSDK7.0 (real machine) as an example, it refers to/Applications/Xcode. app/Contents/Developer/Platforms/iPhoneOS. platform/Developer/SDKs/iPhoneOS7.0.sdk directory.
Note: It seems that "UserHeaderSearchPaths" (or "AlwaysSearchUserPaths") is no longer valid after Xcode4.6. Therefore, it is often useless to configure paths in "UserHeaderSearchPaths", preferably in "HeaderSearchPaths.
88. Error:-[UITableViewdequeueReusableCellWithIdentifier: forIndexPath:]: unrecognizedselector
This is the method after SDK6. in iOS5.0, this method is:
[UITableViewdequeueReusableCellWithIdentifier:]
89. the @ YES Syntax is invalid in iOS5. the error message is Unexpectedtypename 'Bool ': expectedexpression.

In IOS6, @ YES is defined:
# DefineYES (BOOL) 1)
However, in iOS5, @ YES is written with less parentheses:
# DefineYES (BOOL) 1
Therefore, the correct syntax of @ YES in iOS5 should be @ (YES ). For ease of use, you can also fix this Bug in the. pch file:

#if__has_feature(objc_bool)#undefYES#undefNO#defineYES__objc_yes#defineNO__objc_no#endif

The above is the content for iOS development FAQ (7). For more information, see PHP Chinese website (www.php1.cn )!

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.