iOS work notes (i)

Source: Internet
Author: User

Description: Note that some of the trivia of learning iOS, some in the present seems very simple childish, but the right as the footprints!

1.xib development ipad Using a horizontal screen, can be in Xib view settings orientation for landscape,portrait is vertical screen.

2. After declaring the Uitextfield in the. m file, you want to obtain it. Like to get PWD.
@property (nonatomic,weak) Uitextfield *pwd;
Then you can get it with self.pwd.text.

_pwd.text; // This can also be obtained. 

Because Self.view actually calls the PWD get method. It is

1 -(Uitextfield *) pwd{2return  _pwd; 3 }   

3. String comparisons to see if they are equal

1 nsstring *str1 = self.pwdField.text; 2 if ([str1 isequaltostring:@ "123"]) {3// other operations  4 }   

4. Create a new project, if you do not want to use their own viewcontroller and storyboard, delete, then after the new Xib file is prone to problems is the program to run the interface is blank. At this point can be solved, is the definition of the need for a realistic view.
① in the supporting Files folder, edit the Plist file. Leave main storyboard file base name empty (because the storyboard file has been deleted).
② in APPDELEGATE.M.

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions

Add code to the method. If you want to show Loginviewcontroller, you can write this. Fixed format

1 self.window = [[UIWindow alloc]initwithframe:[[uiscreen mainscreen] bounds]; 2 self.window.rootViewController = [[Loginviewcontroller alloc]init]; 3 [Self.window makekeyandvisible]; // make the view visible and appear on the screen

5. When using the Xib file connection, the view must also be connected, otherwise there is no picture of the program, remember.

6. When the control is displayed, the following code is required. Such as:

1 [Self.view addsubview:btn1]; 2 [Self.view addsubview:btn2];

button to add an event, you can use the

1 [btn1 addtarget:self Action: @selector (btnpressed:) forcontrollerevents:uicontroleventtouchupinside]; 2 -(void) btnpressed: (ID) sender{3 UIButton *btn = (UIButton *) Sender ; 4 // event code for the button 5 }   

Of course there are the following forms, preferably using the top. (ID) Sender This parameter refers to the button itself,

1 -(void// The function has no parameters and is error-prone 2     // event 3 }

7. Do not generally define button

1 cgrect frame4 = CGRectMake (430); 2 UIButton *loginbtn = [[UIButton alloc]initwithframe:frame4];

This is usually the way to define

1 loginbtn = [UIButton buttonwithtype:uibuttontyperoundedrect]; 2 loginbtn.frame = frame4;

8. Set the root controller, which needs to be written in Appdelegate. In general, this format is fixed and needs to be
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions{}
Written in. Such as:

1-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions{2     //must be written in the front, otherwise the view does not appear3Self.window =[[UIWindow alloc]initwithframe:[[uiscreen mainscreen] bounds];4     //To display something else, such as Baidu Maps, declare5Self.mapmanager = [[Bmkmanager alloc]init];//If you don't want to show it, delete it.6 7     //define Mainviewcontroller as the root controller8Uinavigationcontroller *controller =[Uinavigationcontroller Alloc]initwithrootviewcontroller:[[mainviewcontroller alloc]init];9Self.window.rootViewController =Controller;Ten     [Self.window makekeyandvisible]; OneSelf.window.backgroundColor =[Uicolor Whitecolor]; A     returnYES; -  -}

If you do not want to use Uinavigationcontroller, you can directly define

Self.window.rootViewController = [[Loginviewcontroller alloc]init];

It is equivalent to deleting the line of code that defines the root controller.
Then the corresponding, the page between the jump there are two ways.

[Self Presentviewcontroller:mainview animated:yes completion:nil]; // view comes with properties [Self.navigationcontroller Pushviewcontroller:mainview animated:true]; // the root controller must be set, otherwise the method is invalid

9. The contents of the home page displayed in the program loading are implemented in the following method, and [super Viewdidload] cannot be omitted.

1 -(void) viewdidload{2  [Super Viewdidload]; 3     Other code   4 }

[Email protected] attribute differences
Weak: Typically used for UI components, such as Uibutton,uilabel,uitextfield.
Strong: For general objects, such as arrays, etc.
Copy: For NSString
Assign: for basic types
There is a difference between xib and pure code, which is strongly referenced by the UI components in the xib in weak,subviews arrays; When you write pure code, you have to use the strong attribute, otherwise you will report

Assigning retained object to weak variable; Object would be released after assignment
Remember.

Nsarray and Nsdictionary, for example, the dictionary itself is a key-value pair, where the key is icon and DESC, different image keys correspond to different values.

1@property (nonatomic,strong) Nsarray *ImageData;2Nsmutabledictionary *image1 =[Nsmutabledictionary dictionary];3image1[@"icon"] =@"Hello";//form of a key-value pair4image1[@"desc"] =@"This is a description of a picture";5 6Nsmutabledictionary *image2 =[Nsmutabledictionary dictionary];7image2[@"icon"] =@"Hello2";8image2[@"desc"] =@"This is an illustration of a picture 2";9 Ten //fast creation of arrays OneSelf.imagedata = @[image1,image2];

When you use more keys in your program, you can define macro constants to prevent the key from being misspelled, such as

#define Iconkey @ "icon"

In the future use of @ "icon", you can use Iconkey directly instead of

iOS work notes (i)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.