Home Backend Development PHP Tutorial iOS development questions (7)

iOS development questions (7)

Jan 20, 2017 am 09:41 AM

71. How to make the size of UIWebView conform to the HTML content?
In iOS5, this is very simple, set the webview delegate, and then implement didFinishLoad: method in the delegate:

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

72. There are multiple Responders in the window, how to quickly release the keyboard
[[UIApplicationsharedApplication]sendAction:@selector(resignFirstResponder)to:nilfrom:nilforEvent:nil];
In this way, all Responders can lose focus at once.
73. How to enable UIWebView to zoom through the "pinch" gesture?
Use the following code:

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

74, Undefinedsymbols:_kCGImageSourceShouldCache, _CGImageSourceCreateWithData, _CGImageSourceCreateImageAtIndex

ImageIO.framework is not imported.

75, expectedmethodtoreaddictionaryelementnotfoundonobjectoftypensdictionary

SDK6.0 has added a "subscript" index to the dictionary, that is, retrieving objects in the dictionary through dictionary[@"key"]. But in SDK5.0, this is illegal. You can create a new header 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<NSCopying>)key;
@end
@interfaceNSArray(subscripts)
-(id)objectAtIndexedSubscript:(NSUInteger)idx;
@end
@interfaceNSMutableArray(subscripts)
-(void)setObject:(id)objatIndexedSubscript:(NSUInteger)idx;
@end
#endif
Copy after login

76, error: -[MKNetworkEnginefreezeOperations]:messagesenttodeallocatedinstance0x1efd4750
This is A memory management error. The MKNetwork framework supports ARC, and memory management problems should not occur. However, due to some bugs in MKNetwork, this problem occurs when MKNetworkEngine is not set to the strong attribute. It is recommended that the MKNetworkEngine object be set to the strong attribute of ViewController.

77. The difference between UIImagePickerControllerSourceTypeSavedPhotosAlbum and UIImagePickerControllerSourceTypePhotoLibrary
UIImagePickerControllerSourceTypePhotoLibrary represents the entire photo library, allowing users to select all photo albums (including camera roll), while UIImagePickerControllerSourceTypeSavedPhotosAlbum only includes camera roll.
78. Warning "Prototypetablecellsmusthaveresueidentifiers"
The Identidfier attribute of Prototypecell (iOS5 template cell) is not filled in, just fill it in the attribute template.
79. How to read the value in info.plist?
The following example code reads the URLSchemes in info.plist:

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

80. How to prevent ActionSheet from automatically disbanding?
UIActionSheet will eventually be automatically dismissed no matter what button is clicked. The best way is to subclass it, add a noAutoDismiss attribute and override the dismissWithClickedButtonIndex method. When this attribute is YES, no dismissal action is performed. When it is NO, the default dismissWithClickedButtonIndex is called:

#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
Copy after login

81 ,Crash when executing RSA_public_encrypt function
This problem is very strange. Using two devices, one with system 6.1 and one with 6.02, the same code works fine in version 6.02, but causes the program to crash in version 6.1:

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

The problem lies in this sentence:

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

6.1 System iPad is a 3G version. Due to the unstable signal of the 3G network (China Unicom 3gnet) used, the rsa public key cannot be obtained frequently, so the rsa parameter appears nil. The 6.0 system iPad is a wifi version and the signal is stable, so there is no such problem. The solution is to check the validity of the rsa parameters.
82. Warning: UITextAlignmentCenterisdeprecatediniOS6
NSTextAlignmentCenter has been replaced by UITextAlignmentCenter. There are some similar alternatives. You can use the following macro:

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

83. -fno-objc-arc cannot be set in Xcode5
Xcode5 uses ARC by default and hides the " CompilerFlags" column, so you cannot set the -fno-objc-arc option of the .m file. 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, so that you can set the -fno- of the .m file. objc-arc flag.
84. Warning: 'ABAddressBookCreate'isdeprecated: firstdeprecatediniOS6.0
This method will be abandoned after iOS6.0 and replaced by the ABAddressBookCreateWithOptions method:

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

85. How to read after iOS6.0 Get your cell phone address book?
After iOS6, the AddressBook framework has changed, especially that the app needs to obtain user authorization to access the mobile address book. Therefore, in addition to using the new ABAddressBookCreateWithOptions initialization method, we also need to use the new ABAddressBookRequestAccessWithCompletion method of the AddressBook framework to know whether the user is authorized:

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

This method has two block parameters success and failure, respectively used to perform two situations of user authorized access: consent and disagreement.
When the code calls the ABAddressBookRequestAccessWithCompletion function, the second parameter is a block, and the granted parameter of the block is used to inform the user whether to agree. If granted is No (disagree), we call the failure block. If granted is Yes (agree), we will call the readAddressBookContacts function to further read the contact information.
readAddressBookContacts is declared as follows:

staticvoidreadAddressBookContacts(ABAddressBookRefaddressBook,void(^completion)(NSArray*contacts)){
//dostuffwithaddressBook
NSArray*contacts=(NSArray*)CFBridgingRelease(ABAddressBookCopyArrayOfAllPeople(addressBook));
completion(contacts);
}
Copy after login

First get all contacts from addressBook (the results are placed in an NSArray array), and then call the completion block (that is, the success block of the fetchContacts method). In completion we can iterate over 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);
}];
}
Copy after login

即在fetchContacts的完成块中对联系人姓名进行中文排序。最后调用completion块。在fetchContacts的错误块中,简单打印错误信息。
调用getAddressBook的示例代码如下:

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

86、ARC警告:PerformSelectormaycausealeakbecauseitsselectorisunknown
这个是ARC下特有的警告,用#pragmaclangdiagnostic宏简单地忽略它即可:

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

87、'libxml/HTMLparser.h'filenotfound
导入libxml2.dylib后出现此错误,尤其是使用ASIHTTP框架的时候。在BuildSettings的HeaderSearchPaths列表中增加“${SDK_DIR}/usr/include/libxml2”一项可解决此问题。
所谓"$(SDK_ROOT)"是指编译目标所使用的SDK的目录,以iPhoneSDK7.0(真机)为例,是指/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk目录。
注意,似乎Xcode4.6以后“UserHeaderSearchPaths”(或者“AlwaysSearchUserPaths”)不再有效,因此在“UserHeaderSearchPaths”中配置路径往往是无用的,最好是配置在“HeaderSearchPaths”中。
88、错误:-[UITableViewdequeueReusableCellWithIdentifier:forIndexPath:]:unrecognizedselector
这是SDK6以后的方法,在iOS5.0中这个方法为:
[UITableViewdequeueReusableCellWithIdentifier:]
89、@YES语法在iOS5中无效,提示错误:Unexpectedtypename'BOOL':expectedexpression

在IOS6中,@YES定义为:
#defineYES((BOOL)1)
但在iOS5中,@YES被少写了一个括号:
#defineYES(BOOL)1
因此@YES在iOS5中的正确写法应当为@(YES)。为了简便,你也可以在.pch文件中修正这个Bug:

#if__has_feature(objc_bool)
#undefYES
#undefNO
#defineYES__objc_yes
#defineNO__objc_no
#endif
Copy after login

以上就是iOS 开发百问(7)的内容,更多相关内容请关注PHP中文网(www.php.cn)!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

The first version of Apple's iOS 18 was exposed to have so many bugs: serious fever, WeChat delay The first version of Apple's iOS 18 was exposed to have so many bugs: serious fever, WeChat delay Jun 13, 2024 pm 09:39 PM

The annual WWDC has ended, and iOS18 is undoubtedly the focus of everyone's attention. Currently, many iPhone users are rushing to upgrade to iOS18, but various system bugs are making people uncomfortable. Some bloggers said that you should be cautious when upgrading to iOS18 because "there are so many bugs." The blogger said that if your iPhone is your main machine, it is recommended not to upgrade to iOS18 because the first version has many bugs. He also summarized several system bugs currently encountered: 1. Switching icon style is stuck, causing the icon not to be displayed. 2. Flashlight width animation is often lost. 3. Douyin App cannot upload videos. 4. WeChat message push is delayed by about 10 seconds. 5 . Occasionally, the phone cannot be made and the screen is black. 6. Severe fever.

Apple re-releases iOS/iPadOS 18 Beta 4 update, version number raised to 22A5316k Apple re-releases iOS/iPadOS 18 Beta 4 update, version number raised to 22A5316k Jul 27, 2024 am 11:06 AM

Thanks to netizens Ji Yinkesi, xxx_x, fried tomatoes, Terrence, and spicy chicken drumsticks for submitting clues! According to news on July 27, Apple today re-released the iOS/iPadOS 18 Beta 4 update for developers. The internal version number was upgraded from 22A5316j to 22A5316k. It is currently unclear the difference between the two Beta 4 version updates. Registered developers can open the "Settings" app, enter the "Software Update" section, click the "Beta Update" option, and then toggle the iOS18/iPadOS18 Developer Beta settings to select the beta version. Downloading and installing the beta version requires an Apple ID associated with a developer account. Reported on July 24, iO

Apple releases open source Swift package for homomorphic encryption, deployed in iOS 18 Apple releases open source Swift package for homomorphic encryption, deployed in iOS 18 Jul 31, 2024 pm 01:10 PM

According to news on July 31, Apple issued a press release yesterday (July 30), announcing the launch of a new open source Swift package (swift-homomorphic-encryption) for enabling homomorphic encryption in the Swift programming language. Note: Homomorphic Encryption (HE) refers to an encryption algorithm that satisfies the homomorphic operation properties of ciphertext. That is, after the data is homomorphically encrypted, specific calculations are performed on the ciphertext, and the obtained ciphertext calculation results are processed at the same time. The plaintext after state decryption is equivalent to directly performing the same calculation on the plaintext data, achieving the "invisibility" of the data. Homomorphic encryption technology can calculate encrypted data without leaking the underlying unencrypted data to the operation process.

Update | Hacker explains how to install Epic Games Store and Fortnite on iPad outside the EU Update | Hacker explains how to install Epic Games Store and Fortnite on iPad outside the EU Aug 18, 2024 am 06:34 AM

Update: Saunders Tech has uploaded a tutorial to his YouTube channel (video embedded below) explaining how to install Fortnite and the Epic Games Store on an iPad outside the EU. However, not only does the process require specific beta versions of iO

New features of Apple's iOS 18 'Boundless Notes” app: expanded Scenes functionality, introduced grid alignment New features of Apple's iOS 18 'Boundless Notes” app: expanded Scenes functionality, introduced grid alignment Jun 02, 2024 pm 05:05 PM

According to news on June 1, technology media AppleInsider published a blog post today, stating that Apple will launch a new navigation function of "Scenes" for the "Freeform" application extension in the iOS18 system, and add new options for object alignment. Introduction to the "Wubianji" application First, let's briefly introduce the "Wubianji" application. The application will be launched in 2022 and has currently launched iOS, iPadOS, macOS15 and visionOS versions. Apple’s official introduction is as follows: “Boundless Notes” is an excellent tool for turning inspiration into reality. Sketch projects, design mood boards, or start brainstorming on a flexible canvas that supports nearly any file type. With iCloud, all your boards

Should iPhone12 ios16 be updated to ios17.5beta3? How is the experience of ios17.5beta3? Should iPhone12 ios16 be updated to ios17.5beta3? How is the experience of ios17.5beta3? Apr 25, 2024 pm 04:52 PM

Practical sharing... As Apple continues to launch new iOS versions, many iPhone users are faced with the choice of whether to upgrade the system. The release of the latest iOS17.5Beta3 has attracted widespread attention, especially for iPhone12 users. Whether they should abandon the existing iOS16 and try the new Beta version has become a question worth discussing. Based on actual experience, this article analyzes the pros and cons of upgrading iPhone 12 to iOS 17.5 Beta 3 to provide a reference for the majority of Apple fans. First of all, we need to make it clear that Beta versions are usually used by developers or early adopters who are willing to take a certain risk. This means that compared to the official version, the Beta version may contain

Apple iOS/iPadOS 18 Developer Preview Beta 4 released: Added CarPlay wallpapers, sorted out settings options, enhanced camera control Apple iOS/iPadOS 18 Developer Preview Beta 4 released: Added CarPlay wallpapers, sorted out settings options, enhanced camera control Jul 24, 2024 am 09:54 AM

Thanks to netizens Spicy Chicken Leg Burger, Soft Media New Friends 2092483, Handwritten Past, DingHao, Xiaoxing_14, Wowotou Eat Big Kou, Feiying Q, Soft Media New Friends 2168428, Slades, Aaron212, Happy Little Hedgehog, Little Earl, Clues for the little milk cat that eats fish! [Click here to go directly to the upgrade tutorial] According to news on July 24, Apple today pushed the iOS/iPadOS18 developer preview version Beta4 update (internal version number: 22A5316j) to iPhone and iPad users. This update is 15 days after the last release. . Carplay Wallpaper Apple has added wallpapers to CarPlay, covering light and dark modes. Its wallpaper style is similar to iPhone

Apple iOS 17.5 RC version released: allows EU iPhone users to download apps from the website Apple iOS 17.5 RC version released: allows EU iPhone users to download apps from the website May 08, 2024 am 09:30 AM

[Click here to go directly to the upgrade tutorial] According to news on May 8, Apple pushed the iOS17.5RC update (internal version number: 21F79) to iPhone users today. This update is 70 days away from the last release. How to upgrade iOS/iPadOS/watchOS/macOS development version and public beta version? To upgrade the iOS/iPadOS17 developer preview version and public beta version, you can refer to the experience shared by friends: Experience Post 1||Experience Post 2||Experience Post 3||Experience Post 4. Starting from the iOS/iPadOS 16.4 Developer Preview Beta 1, you need to register for the Apple Developer Program. After registration, open the system [Settings] [Software Update] to see the upgrade option. Please note that your iPhone or IP

See all articles