61. Warning "adexplicit braces to avoid dangling else"
The so-called "dangerous else" is code similar to this:
i
f(a== 10) printf("TEN"); else printf("NOT TEN"); a = 100;
The compiler thinks that your else clause causes semantics Not sure, what do you mean? Regardless of whether a is equal to 10, a should be assigned a value of 100 after if is executed, or do you only want a to be assigned a value of 100 in the else clause (that is, when a is not equal to 10)?
If it is the former, the correct way to write it should be:
if(a== 10) { printf("TEN"); }else{ printf("NOT TEN"); } a= 100; 如果是后者,正确的写法应该是: if(a== 10) { printf("TEN"); }else{ printf("NOT TEN"); a = 100; }
Of course, for the c/c++/java compiler, this is just a small problem and will not lead to failure to compile. The compiler actually prefers the former, and it automatically handles the first case. But it will warn you that this is a bad coding style. You can ignore this warning with the #pragma clang diagnostic ignored "-Wswitch" macro, or set the compile option MissingBraces and Parentheses to NO.
62. The iPad simulator does not display the Home button
Starting from Xcode 4.3, in order to obtain more space available to the user, the iPad simulator does not display the Home button. You can replace the Home button through the menu "Hardware > Home" or the shortcut key ⇧⌘H.
63. Novisible @interface for 'NSURL' declares the selector 'query'
In iOS6, this method is abandoned, please use NSURL+Parameters instead.
64. certificateidentity 'iphone distribution' appears more than once
This is a duplicate certificate error. You need to delete the duplicate certificates in the keychain before compilation can pass. However, if you restart Xcode, you will find that the previously deleted certificate is back. But when Xcode is restarted, the certificate in Xcode will be imported into the keychain, so just deleting the duplicate certificate in the keychain is ineffective.
I believe that many students are disgusted by this bug in Xcode, but there is no other way except repeatedly (but in vain) deleting the certificate from the keychain. In fact, we can’t blame Xcode alone, but it also has something to do with the “iPhone Configuration Utility Tool”.
These "residual" certificates in Xcode do not exist in regular form. If you installed the "iPhone Configuration Utility", these certificates actually exist in the .app files in the /Users/km-cn/Library/MobileDevice/Applications/ directory. These .apps are actually the "iPhone Configuration Utility" ——The imported app in "Applications". You can use Finder - "Show Package Contents" to view the .app. One of the files named "embedded.mobileprovision" is a "residual" duplicate certificate. You can delete these .apps one by one, or simply delete all .apps in the directory (anyway, as long as the project file exists, you can compile these .apps at any time and import them into the "iPhone Configuration Utility"). Finally, delete the duplicate certificates in Orgnizer and restart Xcode.
65, Application Identifier 'com. ydtf.*' which doesn't match the current setting 'com.ydtf.dlt'
As you can see, these two Application IDs definitely match (* represents a wildcard character ). But this inexplicable error will cause you to never compile. This is definitely another bug in Xcode, first modify CodeSigning to Don't Code Sign, Build, and then modify it back to the correct signature Build.
66. The identity used to sign the executable is no longer valid.
Due to the previous signature problem, it cannot be archived. See question 65 for the solution.
67. Use presentModalViewController to set the size of the pop-up window on iPad
TestViewController*testVC = [[TestViewController alloc] initWithNibName:@"TestViewController"bundle:nil]; testVC.modalPresentationStyle= UIModalPresentationFormSheet; testVC.modalTransitionStyle= UIModalTransitionStyleCrossDissolve; [selfpresentModalViewController:testVC animated:YES]; testVC.view.superview.frame= CGRectMake(0, 0, 649, 397);//it's important to do this afterpresentModalViewController testVC.view.superview.center = self.view.center;
Note: //it'simportant to do this after presentModalViewController. That is, the frame size must be set after [selfpresentModalViewController:testVC animated:YES];!
68. Customize ActionSheet buttons and Popover arrow directions on iPad.
ActionSheet is displayed in Popover mode on iPad. The cancelButton will not be displayed by default (the SDK uses the area outside the Popover instead of the cancelButton. As long as the user clicks on the area outside the Popover, it is equivalent to clicking the Cancel button). If you init an ActionSheet like this:
UIActionSheet* sheet=[[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:@"cancel" destructiveButtonTitle:@"ok" otherButtonTitles:nil];
, only the red destructiveButton will be displayed in the end.
If you have to display cancelButton, you can do this:
UIActionSheet* sheet=[[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:@"cancel",@"ok",nil]; // sheet.cancelButtonIndex=0; sheet.destructiveButtonIndex=1;
After specifying destructiveButtonIndex, the button is displayed in red.
But never specify cancelButtonIndex, because cancelButton will be removed on iPad.
On iPad, the SDK does not provide an API that can modify the arrow direction of actionSheet. The system automatically determines the direction of the arrow display. But we can use the first parameter of showFromRect to change the direction of the arrow:
CGRect r=sender.bounds; r.size.width=2*self.view.bounds.size.width; r.origin.x=-self.view.bounds.size.width+sender.bounds.size.width/2+sender.frame.origin.x; [sheet showFromRect:r inView:sender animated:YES];
This will replace the original left arrow with an up arrow.
In fact, the logic of iOS when judging the pop-up direction of actionSheet is very simple. Wherever there is "enough" space, it will pop up there. When we use the first parameter of showFromRect to "block" all three directions, it can only pop up from the direction we want.
69. setShowAccurateProgress=YES does not work in ASINetworkQueue
Add request.showAccurateProgress= YES before networkQueue.showAccurateProgress= YES, otherwise showAccurateProgress will not take effect. Sample code:
equest.showAccurateProgress=YES; networkQueue.showAccurateProgress=YES; [networkQueue setSuspended:YES]; [networkQueue addOperation:request]; networkQueue.uploadProgressDelegate=self; [networkQueue go];
此外,由于 CFNework 中的一个 Bug,对于小于128K的数据,无法跟踪其上传/下载的精确进度。
70、如何设置 UIWebView 背景色为透明?
在IB中设置 UIWebView 的 Background 属性为 Clear Color 并不能使其背景透明。要达到这个目的,你需要使用以下两句:
[webView setBackgroundColor:[UIColor clearColor]];[webView setOpaque:NO];
以上就是iOS 开发百问(6)的内容,更多相关内容请关注PHP中文网(www.php.cn)!