71, how to make UIWebView size in accordance with the content of HTML?
In IOS 5, this is simple, set the WebView delegate, and then implement Didfinishload in the delegate: method:
-(void) Webviewdidfinishload: (uiwebview *) webview{
cgsize Size=webview. ScrollView. contentsize; //ios 5+
WebView. bounds=cgrectmake(0,0,size. Width, size. height);
}
72, the window has multiple responder, how to quickly release the keyboard
[[uiapplication sharedapplication] sendaction:@selector(resignfirstresponder ) to: nil from: nil forevent: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=[[uiwebview alloc]init];
WebView. autoresizingmask = (uiviewautoresizingflexiblewidth | uiviewautoresizingflexibleheight);
WebView. scalespagetofit=YES;
WebView. multipletouchenabled=YES;
WebView. userinteractionenabled=YES;
74, Undefined Symbols:_kcgimagesourceshouldcache, _cgimagesourcecreatewithdata, _cgimagesourcecreateimageatindex
No imageio.framework imported.
75. Expectedmethod to read dictionary element not found on object of type Nsdictionary
SDK 6.0 begins by adding a "subscript" Index to the dictionary, which means retrieving objects in the dictionary by dictionary[@ "key". However, in SDK 5.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
@interface Nsdictionary (subscripts)
-(ID) Objectforkeyedsubscript: (ID) key;
@end
@interface Nsmutabledictionary (subscripts)
-(void) SetObject: (ID) obj forkeyedsubscript: (id <NSCopying>) key;
@end
@interface Nsarray (subscripts)
-(ID) Objectatindexedsubscript: (Nsuinteger) idx;
@end
@interface Nsmutablearray (subscripts)
-(void) SetObject: (ID) obj atindexedsubscript: (nsuinteger) idx;
@end
#endif
76. Error:-[mknetworkengine freezeoperations]: message sent to deallocated instance0x1efd4750
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.
77. The difference between Uiimagepickercontrollersourcetypesavedphotosalbum and uiimagepickercontrollersourcetypephotolibrary
Uiimagepickercontrollersourcetypephotolibrary represents the entire photo gallery, allowing users to select all albums (including Camera roll), The Uiimagepickercontrollersourcetypesavedphotosalbum only includes the camera roll.
78. Warning "Prototype Tablecells must have resue identifiers"
The Identidfier property of the Prototype cell (IOS 5 template cell) is not filled in and is filled out in the property template.
79, how to read the value in the Info.plist?
The following sample code reads the URL schemes in Info.plist:
The Info.plist isconsidered the Mainbundle.
Mainbundle = [nsbundle mainbundle];
Nsarray* types=[mainbundle objectforinfodictionarykey:@ "Cfbundleurltypes"];
nsdictionary* dictionary=[types objectatindex: 0];
Nsarray* schemes=[dictionary objectforkey:@ "Cfbundleurlschemes"];
NSLog (@ "%@", [Schemes Objectatindex: 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, no dissolve action, call the default Dismisswithclickedbuttonindex:
#import <UIKit/UIKit.h>
@interface Myalertview: Uialertview
@property (nonatomic, assign) BOOL Noautodismiss;
@end
#import "MyAlertView.h"
@implementation Myalertview
-(void) Dismisswithclickedbuttonindex: (nsinteger) buttonindex animated: (BOOL) Animated {
if (self.) Noautodismiss)
return;
[Super dismisswithclickedbuttonindex: Buttonindex animated: 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:
unsigned char buff[2560]={0};
int buffsize = 0;
Buffsize = rsa_public_encrypt ( strlen(cleartext),
(unsigned char*) cleartext, buff, RSA, padding );
The problem is this sentence:
Buffsize = rsa_public_encrypt ( strlen(cleartext),
(unsigned char*) 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: Uitextalignmentcenteris deprecated in IOS 6
Nstextalignmentcenter has been replaced by Uitextalignmentcenter. A similar alternative to some, you can use the following macros:
#ifdef __IPHONE_6_0 //IOS6 and later
# define Uitextalignmentcenter (uitextalignment) nstextalignmentcenter
# define UITEXTALIGNMENTLEFT (uitextalignment) nstextalignmentleft
# define Uitextalignmentright (uitextalignment) nstextalignmentright
# define Uilinebreakmodetailtruncation (Uilinebreakmode) nslinebreakbytruncatingtail
# defineuilinebreakmodemiddletruncation (Uilinebreakmode) nslinebreakbytruncatingmiddle
#endif
83, XCODE5 can not set the-fno-objc-arc
XCODE5 uses ARC by default and hides the "Compiler Flags" column in compile Sources, so you cannot set the-FNO-OBJC-ARC option for. m files. To display the Compiler flags column for the. m file, you can use the menu "View->utilities->hide Utilities" to temporarily close the Utilities window on the right to display the Compiler flags column, This allows you to set the-FNO-OBJC-ARC flag for the. m file.
84. Warning: ' abaddressbookcreate ' is Deprecated:first deprecated in IOS 6.0
After iOS6.0, the method is discarded and replaced with the Abaddressbookcreatewithoptions method:
cferrorref* error=nil;
abaddressbookref addressbook = abaddressbookcreatewithoptions(NULL, error);
85, iOS6.0 later how to read the phone address Book?
After IOS 6, the AddressBook framework has changed, especially if the app accesses the phone's address book and requires user authorization. Therefore, in addition to the need to use the new Abaddressbookcreatewithoptions initialization method, we also need to use the AddressBook framework new Abaddressbookrequestaccesswithcompletion method to learn whether the user is authorized:
+ (void) Fetchcontacts: (void (^) (nsarray *contacts)) Successfailure: (void (^) ( nserror *error)) Failure {
#ifdef __IPHONE_6_0
if (abaddressbookrequestaccesswithcompletion) {
cferrorref err;
abaddressbookref addressbook = abaddressbookcreatewithoptions(NULL, &err);
abaddressbookrequestaccesswithcompletion (AddressBook, ^ (bool Granted, cferrorref error) {
//Abaddressbook doesn ' tgaurantee execution of this block in main thread, but we want our callbacks Tobe
Dispatch_async (dispatch_get_main_queue(), ^{
if (!granted) {
Failure ((__bridge nserror *) error);
} Else {
readaddressbookcontacts (AddressBook, success);
}
Cfrelease (AddressBook);
});
});
}
#else
//On IOS < 6
Abaddressbookref addressbook = 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:
Static voidreadaddressbookcontacts (abaddressbookref addressbook, void (^completion) ( Nsarray *contacts)) {
//do stuff with AddressBook
nsarray *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{
[ self fetchcontacts: ^ (nsarray *contacts) {
nsarray *sortedarray=[contactssortedarrayusingcomparator: ^ (ID A, ID b) {
nsstring* fullname1= (nsstring*)cfbridgingrelease(abrecordcopycompositename( (__bridge abrecordref) (a)));
nsstring* fullname2= (nsstring*)cfbridgingrelease(abrecordcopycompositename( (__bridge abrecordref) (b)));
int len = [fullName1 length] > [fullName2 length]? [fullName2 length]:[fullname1 length];
nslocale *local = [[nslocale alloc] initwithlocaleidentifier:@ "Zh_hans" ];
return [FullName1 Compare: fullName2 options:nscaseinsensitivesearch range: 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:
[addressbookhelper getaddressbook: ^ (nsarray *node) {
NSLog (@ "%@", Nsarray);
}];
86. Arc Warning: performselector cause a leak because itsselector is unknown
This is an ARC-specific warning, with #pragma clang diagnostic macro simply ignore it:
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-warc-performselector-leaks"
[Targetperformselector:sel Withobject:[nsnumber Numberwithbool:yes];
#pragma clang diagnostic pop
87, ' libxml/htmlparser.h ' file not found
This error occurs after importing Libxml2.dylib, especially when using the asihttp framework. Add "${SDK_DIR}/USR/INCLUDE/LIBXML2" to the Header searchpaths list in Build settings to resolve this issue.
The so-called "$ (Sdk_root)" refers to the directory of the SDK used to compile the target, in the case of the IPhone SDK 7.0 (real machine), refers to the/applications/xcode.app/contents/developer/platforms/ IPHONEOS.PLATFORM/DEVELOPER/SDKS/IPHONEOS7.0.SDK directory.
Note that it seems that after Xcode 4.6 "user Header Search Paths" (or "Always search user Paths") is no longer valid, it is often useless to configure the path in "User Headersearch Paths", preferably is configured in "Header searchpaths".
88, Error:-[uitableviewdequeuereusablecellwithidentifier:forindexpath:]: Unrecognized selector
This is the method after SDK 6, in IOS 5.0 This method is:
[Uitableviewdequeuereusablecellwithidentifier:]
89, @YES syntax in iOS5 invalid, prompt error: Unexpected typename ' BOOL ': expected expression
In IOS6, the @YES is defined as:
#define YES ((BOOL) 1)
However, in IOS 5, @YES was written with less than one parenthesis:
#define YES (BOOL) 1
Therefore @YES the correct wording in IOS 5 should be @ (YES). For simplicity, you can also fix this Bug in the. pch file:
#if __has_feature (Objc_bool)
#undef YES
#undef NO
#define YES __objc_yes
#define NO __objc_no
#endif
IOS Development Hundred Questions (7)