Questions about iOS development (9) and questions about ios development
101 compilation error: ld: library notfound for-lPods
This error is often returned when cocoaPods is used in the project (usually when it is release ).
This is because after pod install, cocoaPods will create a new workspace. You must close the project and re-open it. The problem can be solved.
102 why iOS is always eight hours slower than real time
For example, to convert a string to "NSDate. String Conversion to NSDate is generally performed through NSDateFormatter. On iOS, NSDate is stored in GMT, so NSDateFormatter automatically processes the local time of the current time zone of the string, which is about to be converted to Beijing time (string ") change to GMT "). If you directly transmit this NSDate (longlong, the number of seconds or milliseconds since 1970) to the server, the server will regard this time as Beijing time (in fact, it is GMT time ), this results in a time difference of 8 hours.
The correct method is to add time difference based on this NSDate. The time difference calculation requires that you know the current time zone. [NSTimeZonesystemTimeZone] can get the current time zone (East 8), and then use secondsFromGMTForDate: to get the time difference (in seconds) of this time zone (East 8 ). 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 animation in UITableViewController
TableViewController has built-in keyboard animation code. When the input control in the cell pops up the soft keyboard, tableView will automatically scroll up. However, this function may cause a lot of trouble, because sometimes the input control is rolled to an invisible place. Because we cannot modify the Framework Code, in this case, we must discard TableViewController (subclass) instead of general UIViewController + UITableView. But sometimes we have to use TableViewContrller-for example, to use its static cells, we can solve this problem through the following methods. Override the viewWillAppear method in the UITableViewController subclass to disable the behavior of the parent class viewWillAppear. That is, do not call [superviewWillAppear: animated:
-(Void) viewWillAppear :( BOOL) animated {
// Override super method with don 'tcall [super viewWillApper]
}
104. When should I use NSCache?
NSCache Automatically releases a cache object based on the memory pressure (for example, the view is destroyed, or there are too many cached objects ). Therefore, the objects cached by NSCache must be rebuilt. For example, these objects can be downloaded from the network as needed. Otherwise, you should not use NSCache-because the object does not know when it will be destroyed.
Therefore, when using NSCache, you must note that if the retrieved object does not exist in the cache, We must recreate one:
-(CachedObject) getCachedObject :( id) key {
Id * obj = [NSCacheObjectobjectForKey: key];
If (cb = nil ){
Obj = [[CachedObjectalloc] init]; // Recreate cached object
......
}
Return obj;
}
105. Archive problem of Pods on Xcode5
Problem description:
The following error occurs during Archive (debugging may be normal ):
Ld: library not found for-lPods
The problem is that Xcode5.x will detect the architecture of the dependent project, and its settings must be consistent with that of the main project. Otherwise, the dependent project will be rejected (that is, it will not be compiled ).
Solution:
Set their architecture to be consistent with that of the main project under all targets of the Pods project.
106. How to view the Architecture supported by a static library
Use the "lipo-info static library file" command, for example:
Lipo-info Unrar4iOS
Then, the listener will be shown as follows:
Ubuntures in the fat file: Unrar4iOS are: armv7 armv6 i386
107 if some static libraries are introduced in the project, the error "Undefined symbols forarchitecture armv7s/arm64" will be reported in Archive.
As mentioned in question 105. In addition to the solution in issue 105, there is also a solution.
First, check the Architecture of the static library (Refer to Question 106 ). Then modify Scheme to the Architecture supported by the static library. Modify Build Active ubuntureonly in Buid Settings to Yes. Then compile.
108. The UITableView height is incorrect under Autolayout
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 the navigation bar. In this case, the viewDidLayoutSubviews method should be implemented to exclude the impact of constraints:
-(Void) viewDidLayoutSubviews {
_ Table. frame = CGRectMake (0, 0, self. view. frame. size. width, self. view. frame. size. height );
}
109. How do I modify the title of the default return button?
Assume that the navigation is A view --> B View
If you want to change the title of the return button from View B to view A, you only need to use the following code in view:
Self. navigationItem. backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle: @ "return" style: UIBarButtonItemStylePlain target: self action: nil];
View B does not require any operations.
110 is there 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 is "<null>" instead of "(null)" (nil object ).
Since null values (nil) are not allowed to be inserted in the collection object of the O-C and NSNull is not nil, The NSNull object is used to indicate that the set is empty (indicating that the list ends ). In addition, unlike nil, sending a message to an NSNull will cause an exception.
NSNull has a unique method: [NSNull null] You can use it to test whether an object is NSNull:
BOOL isNSNull (id any ){
Return [any isEqual: [NSNullnull];
}