IOS Development Hundred Questions (7)

Source: Internet
Author: User
71, how to make UIWebView size in accordance with the content of HTML?
In IOS5, this is 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, the window has multiple responder, how to quickly release the keyboard
[[Uiapplicationsharedapplication]sendaction: @selector (Resignfirstresponder) To:nilfrom:nilforEvent:nil];
This allows all responder to lose focus at once.
73, how to let UIWebView through "pinch" gesture to zoom?
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

No imageio.framework imported.

75, Expectedmethodtoreaddictionaryelementnotfoundonobjectoftypensdictionary

SDK6.0 began to add a "subscript" Index to the dictionary, which means retrieving objects in the dictionary by dictionary[@ "key". But in the SDK5.0, this is illegal. You can create a new header file in your project nsobject+subscripts.h to solve this problem with the following:

#if__IPHONE_OS_VERSION_MAX_ALLOWED <60000@interfacensdictionary (subscripts)-(ID) Objectforkeyedsubscript: (ID) Key; @end @interfacensmutabledictionary (subscripts)-(void) SetObject: (ID) objforkeyedsubscript: (id<nscopying >) 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, which should not have been a memory management issue, but because of some bugs in mknetwork, the problem occurs when Mknetworkengine is not set to the strong property. It is recommended that the Mknetworkengine object be set to the strong property of Viewcontroller. The difference between

77, Uiimagepickercontrollersourcetypesavedphotosalbum, and Uiimagepickercontrollersourcetypephotolibrary The
Uiimagepickercontrollersourcetypephotolibrary represents the entire photo gallery, allowing the user to select all albums (including Camera roll), The Uiimagepickercontrollersourcetypesavedphotosalbum only includes the camera roll.
78, the Identidfier property of the warning "prototypetablecellsmusthaveresueidentifiers"
Prototypecell (iOS5 template cell) is not filled in, so fill in the property template.
79, how to read the values in Info.plist?
The following sample code reads Urlschemes in Info.plist:

Theinfo.plistisconsideredthemainbundle.mainbundle=[nsbundlemainbundle]; nsarray*types=[mainbundleobjectforinfodictionarykey:@ "Cfbundleurltypes"]; NSDICTIONARY*DICTIONARY=[TYPESOBJECTATINDEX:0]; nsarray*schemes=[dictionaryobjectforkey:@ "Cfbundleurlschemes"]; NSLog (@ "%@", [schemesobjectatindex:0]);

80, how to let ationsheet not automatically dissolved?
Uiactionsheet No matter what button is clicked, it will be dissolved automatically eventually. The best way is to subclass it, add a Noautodismiss property and override the Dismisswithclickedbuttonindex method, and when this property is yes, the dissolve action is not performed. The default dismisswithclickedbuttonindex is called when no:

#import <UIKit/UIKit.h> @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 rsa_public_encrypt function
This question is very strange. Using two devices, one system is 6.1, one system is 6.02, the same code is normal in the 6.02 version, and the program crashes in the 6.1 version:

Unsignedcharbuff[2560]={0};intbuffsize=0;buffsize=rsa_public_encrypt (strlen (cleartext), (unsignedchar*) cleartext,buff,rsa,padding);

The problem is this sentence:

Buffsize=rsa_public_encrypt (strlen (cleartext), (unsignedchar*) cleartext,buff,rsa,padding);

6.1 System ipad 3G version, due to the use of the 3G network (Unicom 3gnet) signal instability, resulting in RSA public key is often not available, so the RSA parameters appear nil. and 6.0 system ipad for WiFi version, signal stability, so no this problem. The workaround is to check the validity of the RSA parameters.
82. Warning: UITextAlignmentCenterisdeprecatediniOS6
Nstextalignmentcenter has been replaced by Uitextalignmentcenter. A similar alternative to some, 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, XCODE5 can not set the-fno-objc-arc
XCODE5 uses arc by default and hides the "compilerflags" column in Compilesources, so you cannot set the-FNO-OBJC-ARC option for. m files. To display 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, This allows you to set the-FNO-OBJC-ARC flag for the. m file.
84. Warning: ' Abaddressbookcreate ' isdeprecated:firstdeprecatedinios6.0
After iOS6.0, the method is discarded and replaced with the Abaddressbookcreatewithoptions method:

Cferrorref*error=nil; Abaddressbookrefaddressbook=abaddressbookcreatewithoptions (Null,error);

85, iOS6.0 later how to read the phone address Book?
After the iOS6, the AddressBook framework changed, especially when the app accessed the phone's address book and needed authorization from the user. Therefore, in addition to the need to use the new Abaddressbookcreatewithoptions initialization method, We also need to use the new Abaddressbookrequestaccesswithcompletion method of the AddressBook framework to learn 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, respectively, for performing user-authorized access in two cases: consent and disagreement.
When the code calls the Abaddressbookrequestaccesswithcompletion function, the 2nd parameter is a block, and the granted parameter of the block is used to tell the user whether to agree. If granted is no (disagree), we call the failure block. If granted is yes (consent), we will call the Readaddressbookcontacts function to read the contact information further.
Readaddressbookcontacts declares as follows:

Staticvoidreadaddressbookcontacts (Abaddressbookrefaddressbook,void (^completion) (NSArray*contacts)) {// Dostuffwithaddressbooknsarray*contacts= (nsarray*) cfbridgingrelease (Abaddressbookcopyarrayofallpeople ( AddressBook)); completion (contacts);}

First get all the contacts from AddressBook (the result is placed in a nsarray array), and then call the completion block (the success block of the Fetchcontacts method). In completion we can iterate over the arrays.
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 name is sorted in Chinese in the completion block of the fetchcontacts. Finally call the completion block. In the fetchcontacts error block, simply print the error message.
The sample code for calling Getaddressbook is as follows:

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

86. Arc Warning: Performselectormaycausealeakbecauseitsselectorisunknown
This is an arc-specific warning, simply ignore it with the #pragmaclangdiagnostic macro:

#pragmaclangdiagnosticpush #pragmaclangdiagnosticignored "-warc-performselector-leaks" [Targetperformselector: Selwithobject:[nsnumbernumberwithbool:yes]]; #pragmaclangdiagnosticpop

This error occurs after

87, ' Libxml/htmlparser.h ' filenotfound
Import libxml2.dylib, especially when using the asihttp framework. Add a "${SDK_DIR}/USR/INCLUDE/LIBXML2" to the Headersearchpaths list in buildsettings to resolve this issue. The
so-called "$ (Sdk_root)" refers to the directory of the SDK used to compile the target, taking iPhoneSDK7.0 (real machine) as an example, refers to/applications/xcode.app/contents/developer/platforms /IPHONEOS.PLATFORM/DEVELOPER/SDKS/IPHONEOS7.0.SDK directory.
Note that it seems that Xcode4.6 later "userheadersearchpaths" (or "alwayssearchuserpaths") is no longer valid, so the "userheadersearchpaths" It is often useless to configure the path in, preferably in "headersearchpaths".
88, Error:-[uitableviewdequeuereusablecellwithidentifier:forindexpath:]:unrecognizedselector
This is the method after SDK6, In iOS5.0, this method is:
[uitableviewdequeuereusablecellwithidentifier:]
89, @YES syntax is not valid in IOS5, Hint error: Unexpectedtypename ' BOOL ': expectedexpression

in IOS6, @YES defined as:
#defineYES ((BOOL) 1)
But in iOS5, @ YES is less than one parenthesis:
#defineYES (BOOL) 1
So the correct wording for @yes in iOS5 should be @ (YES). For simplicity, 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 iOS Development Hundred questions (7) content, more relevant content please pay attention to topic.alibabacloud.com (www.php.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.