Program Log--ios "text length--button interaction with label" program

Source: Internet
Author: User

My study Log 003: "Text length--button interaction with label" program

Give me the tools to do the program: Mac OS X virtual machine 10.9.3 Xcode6 Baidu-^-^ Reference IPhone30 days Proficient (this book is outdated, but there is a certain reference value, can guide the correct direction of learning).


No new knowledge points, just put the steps and code.


Xcode new Singleview Program, the VIEWCONTROLLOR.H code is as follows:

#import <UIKit/UIKit.h>

#import <Foundation/Foundation.h>

@interface viewcontroller:uiviewcontroller{

Iboutlet Uitextfield *textfield;

Iboutlet UILabel *label;

}

@property (Nonatomic,retain) Uitextfield *textfield;

@property (Nonatomic,retain) UILabel *label;

-(ibaction) Click;

@end

VIEWCONTROLLOR.M file

#import "ViewController.h"

@implementation Viewcontroller

@systhesize Textfield,label;

-(void) viewdidload{

[Super Viewdidload];

Label.text = @ "Please enter text";

}

-(Ibaction) click{

This method is called every time a button is clicked.

int count = TextField.text.length;

if (count>20) {

Label.text = @ "More than 20 words entered with spaces and punctuation";

Textfield.text = NULL;

}

else{

NSString *result = [NSString stringwithformat:@ "The number of words entered is%d", Count];

Label.text = result;

Textfield.text = NULL;

}

}

-(void) didreceivememorywarning{

[Super didreceivedmemorywarning];

}

Storyboared Processing:

The first thing to do is to create the Textfield,button,label control, because the previous code has already created the objects for these controls, then select each control in the respective, hold down the CTRL key, and drag the left mouse button to the corresponding object inside the. h file.

The operation is OK. This step may have not understood, direct, look at the diagram itself operation should be able to, not this method of attention to the details of the figure.



Talk about the problems I have encountered and what I do not understand: the problems encountered:

1. Run the time to encounter a warning: the simulator can ' t be launched ..... It probably means that my simulator program is still in use, how can I run another program? This is just a matter of forcing the Xcode to close,

Force off shortcut key is commend+q (virtual machine does not have commend button, win key instead can).

2. I forgot to add the phrase "#import <Foundation/Foundation.h>" when I wrote the ViewController.h file, which led to my program "THREAD1:SIGNALSIGABRT ..." Such a warning, so be careful when you write the program later.

3. When opening the program, Xcode also warns me "No signing identity Dound" This is a signature warning, meaning that there is no signature identification. If you are using the simulator to tune the program is not related, you can not control it.

Knowledge points to be solved:

@prperty and @systhesize

I summed it up in my second log, but now it seems that it is too much food. http://blog.csdn.net/v7595v/article/details/46833209

Now only summarize @Prperty with @systhesize, can chew, as follows:

Objective-c language keyword, used in pairing with @synthesize. xcode4.5 and later versions, @synthesize can omit the person class as an example: in the. h file: @interface person:nsobject{nsstring * _name; NSString * _SEX; Nsinteger _age;} @property NSString * NAME; @property nsstring * sex; @property nsinteger age; Three properties declared: Name,sex,age, 3 corresponding setter and get are generated by default The TER method is in. M file: @implementation person@synthesize name = _name; @synthesize sex = _sex; @synthesize age = _age; @end means implement 3 setter and get The Ter method, where name = _name indicates that the instance variable that is manipulated in getter and setter methods is _name, and if _name,_age,_sex is omitted, it will be in. H file generates an instance variable with the same name Name,sex,age (note: There is no underscore here), and the generated setter and getter methods manipulate the instance variable name,sex,age, so _name,_sex,_age is not manipulated. In iOS5 . After 0, @synthesize can also omit to write at this time. H file only write @ property, the compiler will automatically generate the corresponding instance variable, the name of the instance variable is underlined before the attribute name.


This is my Baidu encyclopedia copy over the information, according to its words, I can remove the ViewController.h file inside the @interface{} inside the definition of the instance variable, while removing the @systhesize, only write @property can be. But, it's okay to remove the @systhesize, but after removing the instance variable inside the @interface{}, you can't associate the @property in the storyboard and. h files with Ctrl. So you can add only the instance variables defined in the @interface{}. Also, I added the instance variable is the same as the @property modified variable name, no "_" to distinguish, but there is no error, then I will temporarily first in this convenient way to write code.



IB is interface builed:

The book and the Internet always say that IB is interfacebuiled, about ibaction and iboutlet I have solved this problem in the first article of my program log, http://blog.csdn.net/v7595v/article/details/46831265

What is interfacebuiled?

Read the Baidu Encyclopedia Http://baike.baidu.com/link?url= Wupocb4zlkquhj8nb46slu4phwaxgc0v56fyahesmedkvia833e3zzqquyqi-nulgwzhd-3swutziy3dcjqbea

It's pointless for IB to dig deeper.




Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Program Log--ios "text length--button interaction with label" program

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.