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)!

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

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

Dreamweaver CS6
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
