iOS development questions (9)
101. Compilation error: ld: library not found for -lPods
This error often occurs when cocoaPods is used in the project (usually during release).
This is because cocoaPods will create a new workspace after pod install. You must close the project and reopen it. The problem is solved.
102. Why is iOS time always 8 hours slower than the real time
For example, a Beijing time "2014-4-4 22:00" (string) needs to be converted into NSDate. Conversion of strings to NSDate is generally performed through NSDateFormatter. On iOS, NSDate is stored in GMT time, so NSDateFormatter will automatically process the local time of the current time zone of the string, that is, convert the converted Beijing time (string "2014-4-4 22:00") into GMT time (" 2014-4-4 14:00"). If you directly pass this NSDate (longlong, the number of seconds or milliseconds since 1970) to the server, the server will use this time as Beijing time (actually it is GMT time), which results in a time difference of 8 hours.
The correct approach is to add the time difference based on this NSDate. The calculation of the time difference requires knowing the current time zone. [NSTimeZonesystemTimeZone] can get the current time zone (East 8 Zone), and then use the secondsFromGMTForDate: method to get the time difference (in seconds) of this time zone (East 8 Zone). The code is as follows:
NSDateFormatter* df=[NSDateFormatter new]; // [dfsetLocale:[NSLocale currentLocale]]; df.dateFormat=@"yyyy-MM-dd HH:mm"; NSDate* date=[dfdateFromString:@"2014-4-4 22:00"]; NSTimeZone *zone =[NSTimeZone systemTimeZone]; NSInteger interval = [zonesecondsFromGMTForDate: date]; NSDate *localeDate =[date dateByAddingTimeInterval:interval]; NSLog(@"%@",localeDate);
103. Disable keyboard pop-up animation in UITableViewController
TableViewController has built-in code for keyboard pop-up animation. When the input control in the cell pops up the soft keyboard, the tableView will automatically move up scroll. But this feature sometimes causes big trouble, because sometimes the input control will be scrolled to an invisible place. Since we cannot modify the framework code, in this case we must give up using TableViewController (subclassing) and use general UIViewController+UITableView instead. But sometimes we have to use TableViewContrller - for example, if we want to use its static cells, we can solve it through the following methods. Override the viewWillAppear method in the UITableViewController subclass to disable the viewWillAppear behavior of the parent class. That is, don't call [superviewWillAppear:animated]:
-(void)viewWillAppear:(BOOL)animated{ // Override super method with don'tcall [super viewWillApper] }
104. When should you use NSCache
NSCache will automatically release one of the cache objects based on memory pressure (for example, the view is destroyed, Or there are too many cached objects). Therefore, the objects cached by NSCache must be rebuildable, such as these objects - data that can be downloaded from the network when needed. Otherwise, you shouldn't use NSCache - the object will be destroyed at some point.
Therefore, when using NSCache, you must pay attention. If the retrieved object does not exist in the cache, we must rebuild one:
-(CachedObject)getCachedObject:(id)key{ id* obj=[NSCacheObjectobjectForKey:key]; if (cb==nil) { obj=[[CachedObjectalloc]init]; // Recreate cached object …… } return obj; }
105. Pods Archive problem on Xcode5
Problem description :
The following error occurs when archive (may be normal when debugging):
ld: library not found for -lPods
The problem is because Xcode5.x will now detect the architecture of dependent projects, and its settings must be consistent with The main project must be consistent, otherwise the dependent project will be rejected (that is, it will not be compiled).
Solution:
Under all targets of the Pods project, set their architecture to be consistent with the main project.
106. How to check the Architecture supported by a static library
Use the "lipo -info static library file" command, for example:
lipo -info Unrar4iOS
Then the terminal will display as follows:
Architectures in the fat file: Unrar4iOS are: armv7 armv6 i386
107. Introducing certain static libraries into the project will cause "Undefined symbols for architecture armv7s/arm64" errors in Archive reports
As mentioned in question 105. In addition to using the solution in question 105, there is another workaround.
First check the Architecture of the static library (refer to question 106). Then modify Scheme to support the Architecture of the static library. Then modify Build Active ArchitectureOnly in Buid Settings (compile only for the selected architecture) and change the value to Yes. Then compile it.
108. Under Autolayout, the height of UITableView is incorrect
Under Autolayout, if there is a navigation bar, the UITableView on the view is restricted by constraints, and the runtime height is reset by constraints to the height without navigation bar. At this time, the viewDidLayoutSubviews method should be implemented to eliminate the influence of constraints:
- (void)viewDidLayoutSubviews { _table.frame=CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height); }
109. How to modify the title of the default return button?
Assume the navigation is: A view -->B view
If you want to change the title of the return button of B view to return to A view, just use the following code in A view:
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:nil]; B视图不用做任何操作。
110. There is an empty object, but it is neither nil nor null?
It is NSNull. You can print this object (using the po command or NSLog), and the printed result will be "
Since O-C collection objects do not allow the insertion of null values (nil), and NSNull is not nil, the NSNull object is used to indicate that the collection is empty (indicating the end of the list). Also, unlike nil, sending a message to an NSNull will cause an exception.
NSNull has the only method: [NSNull null] You can use it to test whether an object is NSNull:
BOOL isNSNull(id any){ return [any isEqual:[NSNullnull]]; }
以上就是iOS 开发百问(9)的内容,更多相关内容请关注PHP中文网(www.php.cn)!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



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.

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

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: 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

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

[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

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

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
