Home  >  Article  >  Backend Development  >  iOS development questions (1)

iOS development questions (1)

黄舟
黄舟Original
2017-01-20 09:23:321024browse

1. Set the size of ImagePicker
ImagePicker is always displayed at the default size in Popover Controller, and setting the popoverContentSize attribute seems useless. The solution is to "include" the ImagePicker into a custom ViewController, and then presentPopover this ViewController:

UIViewController *containerController = [[UIViewController alloc] init];
containerController.contentSizeForViewInPopover = CGSizeMake(600,self.view.frame.size.height);
[containerController.viewaddSubview:_imagePicker.view];
_popController= [[UIPopoverController alloc] initWithContentViewController:containerController];
CGPoint p=[self.view convertPoint:button.center
fromView:sender.superview];
[_popController presentPopoverFromRect:(CGRect){p,CGSizeZero}
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
[_imagePicker.view setFrame:containerController.view.frame];// 很重要

Note that the width of the popover is at most 600. In addition, _imagePicker must be init once before each presentPopoverFromRect, otherwise the display position will be incorrect.
2. The problem of garbled Chinese file names in uploaded files
Use URL Encode to encode the file name on the iOS client, and then use URL Decode to decode it on the server.
Client:

NSStringEncodingenc=NSUTF8StringEncoding;
[request setData:datawithFileName [filename stringByAddingPercentEscapesUsingEncoding:enc]
andContentType:@"application/octet-stream" forKey:key];

Server:

String filename=request.getParameter(“upload_file”);
filename=URLDecode.decode(s,”utf-8”);

3, Mac 64 bit Device
Sometimes after updating the project from SVN, Scheme will be displayed as Mac 64 bit Device and does not allow running programs. At this time, you only need to reset the DeploymentTarget of Target (set to simulator or debugging device).
4. Remove the NSLog of the debugger
The compilation parameter Optimize Level is set according to different versions. For example, the Debug version is None, and the Release version is Fastest, Smallest. In this way, we can redefine the NSLog function based on this parameter:

#ifndef __OPTIMIZE__
#define NSLog(...)NSLog(__VA_ARGS__)
#else
#define NSLog(...) {}
#endif

5. Warning: no previous prototye for function
According to the c specification, if the function has no parameters, use void as the function parameter.
The function declaration should use "void functionA(void);" instead of "void functionA();".
6. Array sorting
Method 1:

- (NSComparisonResult)compare:(Person *)otherObject {
return [self.birthDatecompare:otherObject.birthDate];
}
NSArray *sortedArray;
sortedArray = [drinkDetails sortedArrayUsingSelector:@selector(compare:)];

Method two:

NSSortDescriptor *sortDescriptor;
sortDescriptor = [[[NSSortDescriptor alloc]initWithKey:@"birthDate"
ascending:YES] autorelease];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
NSArray *sortedArray;
sortedArray = [drinkDetails sortedArrayUsingDescriptors:sortDescriptors];

Method three (10.6+):

NSArray *sortedArray;
sortedArray = [drinkDetails sortedArrayUsingComparator:^(id a, id b) {
NSDate *first =[(Person*)a birthDate];
NSDate *second =[(Person*)b birthDate];
return [firstcompare:second];
}];

7. Where is the build directory of Xcode 4?
Xcode 4 has made many changes. You won't be able to find the build directory, and you won't be able to find the Products file group. So where does it put the executable file generated after the project is compiled? The answer is the "{USERNAME}/Library/Developer/Xcode/DerivedData/{PROJECT_NAME_AND_RANDOM_CRAP}/Build/Products/{BUILD_TYPE}/{PROJECT_NAME}.app" directory.
8. Warning: no rule to process file
Xcode attempts to detect each file type. When it thinks a file is of type "source file" (such as a .js file), it always tries to add it to Compile Sources and tries to compile it. The solution to this warning is to move such files from the Compile Sources of Build Phases to Copy Bundle Resources.
9. Warning: 'initWithFrame:reuseIdentifier:'is deprecated
This method will be abandoned in subsequent versions. Please use
- initWithStyle:reuseIdentifier:
10, itms-services does not work
itms-services is recognized by apple/iphone as a special word, it will verify the certificate specified in the provisioning profile and install it .
Before installing this .ipa file, verify the profisioning profile, which will be connected to "ax.init.itunes.apple.com" and "ocsp.apple.com".
If you are on an intranet, please check whether the above address is accessible. If not, you won't be able to use OTA to install the app. Requires iOS 4.0 or above.
Note: Inability to access the above address will not affect the installation. However, iOS will check whether the certificate is legal through the above address at runtime. If the installation is legal, iOS will cache the check results (7 days).

The above is the content of iOS development questions (1). For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


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