When we write the program, the width of the screen is not fixed, such as writing 320,480, because we want to adapt to different mobile phones. One common way is to set the width height in the. pch file, because the. pch is a precompiled file that can be accessed globally.
#define ScreenHeight [UIScreen mainscreen].bounds.size.hight;
#define ScreenWidth [UIScreen mainscreen].bounds.size.width;
precompiled file Creation:
1. Create header file2. Macro definition within the header3. buildsetting inside search prefix, find prefix header, double-click Value, drag the header file in, set as precompiled file Note: Set the path macro $SRCROOT represents the project file path question two:
This is a simple question, not a skill at all, but sometimes we ignore this usage. is to set the background image for UIView.
view.backgroundcolor = [Uicolor colorwithpatternimage:[uiimage imagenamed: @background. png"]];
question three:
Our picture is square, and we want it to appear in the interface with a shape like a circle or an ellipse.
_image = [[Uiimageview alloc]initwithframe:cgrectmake (0,0, ; // Different sizes, different shapes = YES;
Question four:
Three ways to get the main window.
UIApplication *app=[uiapplication shareapplication]; 1. UIWindow *window = App.keywindow; 2. UIWindow *window = app.delegate. window; 3. UIWindow *window = [app.windows objectatindex:0];
Of course we can also use ligatures method: For example: UIWindow *window = [UIApplication Shareapplication].delegate.window;
question five:
We sometimes accidentally modify the system's API, or some other operations, the following problems arise?
Error message: Fatal error:file/application ....
Note:after Modifying system headers, please delete the module cache at/users .....
Workaround: Go to/users. This folder, delete the files inside, and then clean the program can be resolved.
question six:
How do we make the timer pause and start, not turn on and off.
Nstimer *timer = [Nstimer sch ...]; [Timer setfiredate: [NSDate distantfuture]; // Pause [Timer setfiredate: [NSDate Distantpass] // Start
question seven:
In the network request, if the request body has Chinese characters, the request will be wrong, how to solve?
Suppose the request body is: NSString *urlstring= @ "Http://v.juhe.cn/weather/index?cityname= Beijing";
Because there are kanji characters, the request will go wrong. Treatment methods:
urlstring = [urlstring stringbyaddingpercentescapesusingencoding:nsutf8stringencoding];
question eight:
How to make our picture enlarged without distortion.
_image = [[UIImage imagenamed:@ "a.png"]stretchableimagewithleftcapwidth:20 topcapheight:];
question nine:
Arc and non-arc mixed.
If you are using a non-arc, imported ARC code file in your project, you need to include the-FOBJC-ARC tag in the ARC mode file code
If you are using ARC mode in your project, add the-FNO-OBJC-ARC tag to the non-ARC mode code file
Add Tag method: Target->build phases->compile sources, double-click the corresponding. m file and enter the label in the popup box.
Question 10:
In the custom Xib cell, the Uiimageview graph does not match the defined size, and may be displayed according to the original image.
The possible problem is that Uiimageview is named ImageView, which conflicts with the name of the system and the picture does not appear as expected.
question 11:
The UITableView agent does not call.
It is common that the agent is not set.
Another case is inheritance error, which is generally inherited uiviewcontroller, and if the inheritance relationship is wrong, the proxy method is not called.
Question 12:
How to find the view on Xib, there may be more than one, can be received with an array.
Nsarray *nib = [[NSBundle mainbundle]loadnibnamed:@ 'customview' owner:self options: Nil]; // get the first UIView *tmpcustomview = [nib Objectatindex:0
Question 13:determines the size of the text, depending on the text content
CGRect rect = [str boundingrectwithsize:cgsizemake (maxfloat) options: Nsstringdrawinguseslinefragmentorigin attributes:@{nsfontattributename:[uifont systemFontOfSize:]} Context:nil];
Question 14:
Adding a UIView to the UIButton will make the UIButton click event Unresponsive, and the workaround is to change the interactivity of the UIView to No.
Question 15:
If there is scrollview in the interface and there is a navigation bar in the interface, the view controller sets a 64 offset to ScrollView by default.
We can use Self.automaticalladjustsscrollviewinsets = No,scrollview is not offset.
Tabbar height 49, navigation plus status bar height 64.
Question 16:we can use the following method to print out the class, and the function:
NSLog (@ "%s", __function__);
Question 17:
Grammar Sugar basic notation:
NSString *str =@"123"; Nsdictionary*dict = @{@"name":@"WYG",@" Age":@" A",@"Sex":@" Boy"}; Nsarray*arr = @[@"1",@"2"]; NSString*st = arr[1]; NSNumber*intnumber = @123; NSNumber*boolnumber = @NO;question 18:when Uiscrollview was created, the subviews was printed, and two more were found because the horizontal bar and the vertical bar were added, and their properties were set to No.
Ios-Frequently Asked Questions