Home > Backend Development > PHP Tutorial > iOS development questions (9)

iOS development questions (9)

黄舟
Release: 2023-03-05 06:48:02
Original
1201 people have browsed it

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);
Copy after login

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]
}
Copy after login

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;
}
Copy after login

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);
}
Copy after login

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视图不用做任何操作。
Copy after login

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 "" instead of "(null)" (nil object).
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]];
}
Copy after login

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

Related labels:
source: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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template