iOS work notes (10)

Source: Internet
Author: User

1. About TextField

There are two options when doing something, such as handling an account or password when logged in.
① login button can be clicked, but will use Alertview to prompt "account or password is empty" message.
② at this time the login button is not clickable, only the account and password are values, you can click.
Two methods recommend the second, the experience is better. You need to implement uitextfielddelegate at this time, and

1 -(BOOL) Textfieldshouldclear: (Uitextfield *) textfield{2     //  Make the button non-clickable while emptying the content 3     _savebtn.enabled = No; 4     return YES; 5 }6// This method indicates whether to allow content to be emptied on request.

2. When there is more than one uiactionsheet in a view, you can set different tag values for Actionsheet and then process the options according to the tag value. Such as

1- (void) Actionsheet: (Uiactionsheet *) Actionsheet Clickedbuttonatindex: (nsinteger) buttonindex{2     Switch(Actionsheet.tag) {3          Case 1:4             Switch(buttonindex) {5                  Case 0:6NSLog (@"Viewed 0");7                      Break;8                     9                 default:Ten                      Break; One             } A              Break; -          -          Case 2: the             Switch(buttonindex) { -                  Case 0: -NSLog (@"Viewed 3"); -                      Break; +                      -                  Case 1: +NSLog (@"Viewed 4"); A                      Break; at                      -                 default: -                      Break; -             } -              Break; -              in         default: -              Break; to     } +}

3. Handling of proxies and assignment methods.

There are two methods, one proxy method, and the other is the cellforrowatindexpath that assigns a value to the cell.

// The proxy method, which executes later than Cellforrowatindexpath, but will callback. -(void) GetData: (Nsarray *) arr{    //}-(UITableViewCell *) TableView: ( UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath {    //}

There is an array of arr, which is assigned by the proxy method, and then assigns the data in Arr to the cell. However, when the program runs, Cellforrowatindexpath is executed first, so you need to set a value to mark whether ARR is assigned a value.

The processing method is to set a bool value of _isvalued, set its initial value to No, then set to Yes in the proxy method, and then assign a value to the cell.

1 //This method executes first than the Proxy method2-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath {3     if(_isvalued) {4         //Perform assignment operations5}Else {6         //Set Blank cell7     }8 }9 Ten-(void) GetData: (Nsarray *) arr{ One     //Other Operations A     //when the assignment is complete, set the -_isvalued =YES; -}

The key is the establishment of _isvalue.

The [email protected] method can be defined and then used directly

For parameters that are not

1 Sel sel = @selector (refreshpersondatabynotification); 2 Object : nil]; 3 4 // Refresh Data 5 -(void) refreshpersondatabynotification{6    [_tableview Refreshload]; 7 }

There are parameters that can be written like this

Sel sel = @selector (write:andage:); -(void) write andage: (NSString *) age{    //}

5. If a different. M has multiple operations, each of which sends a notification, but the action performs the same task, then when registering listeners, you do not need to register multiple notifications of different names, just one.

Such as:

1 Object : nil]; 2 Object : nil]; 3 object: nil];

Total can be 1, as long as the name of the notification unified.

object: nil];

When declaring the name of a notification, it is recommended to use

Const @" Notiname ";

Warning: Sending ' const nsstring *__strong ' to parameter of type ' NSString ' discards qualifiers by using the following notation

Const @" Notiname ";

6. A number of reviews of inheritance

When a subclass inherits from a parent class, the subclass takes on all methods and properties of the public nature of the parent class. In the UIView. h of a parent class.

1 @interface viewfather:uiview{      2@public  3     UILabel *_lab; 4 }  5  6 @property (nonatomic,strong) UIButton *firstbtn; 7 @property (nonatomic,strong) UIButton *secondbtn; 8 @property (nonatomic,strong) UIButton *thirdbtn; 9 Ten @end

After the subclass inherits,

@interface Viewson:viewfather @end

Then you can get property-modified properties by SELF.FIRSTBTN, but if you want to get _lab, you can only pass

Self->_lab

To obtain, and is similar to

{    @public*    _lab;}

In this case, if you want the subclass to inherit, you can only write to the parent class. h, which is not available in the subclass in. M.
For methods, if the method name is the same, the child class overrides the method in the parent class. If different, two methods are executed. As follows:
The parent class has

1UIButton *firbtn =[UIButton Buttonwithtype:uibuttontypecustom];2[Firbtn Settitle:@"first one"Forstate:uicontrolstatenormal];3 [firbtn Settitlecolor:[uicolor Blackcolor] forstate:uicontrolstatenormal];4Firbtn.frame = CGRectMake ( -, -, -, -);5FirBtn.layer.cornerRadius = -;6Firbtn.backgroundcolor =[Uicolor Browncolor];7SELF.FIRSTBTN =firbtn;8 [self.firstbtn addtarget:self Action: @selector (ALERTMSG) forcontrolevents:uicontroleventtouchupinside];9 [self addsubview:firbtn];Ten  One-(void) alertmsg{ AUiactionsheet *sheet = [[Uiactionsheet alloc]initwithtitle:nilDelegate: Self Cancelbuttontitle:@"Cancel"Destructivebuttontitle:nil Otherbuttontitles:@"First Item",@"Second Item",@"Third Item", nil]; - [sheet showinview:self]; -}

Subclass, there are

1 [self.firstbtn addtarget:self Action: @selector (ALERTMSG2) forcontrolevents:uicontroleventtouchupinside];2 3-(void) alertmsg2{4Uiactionsheet *sheet = [[Uiactionsheet alloc]initwithtitle:nilDelegate: Self Cancelbuttontitle:@"Cancel"Destructivebuttontitle:nil Otherbuttontitles:@"haha",@"Hey",@"Hoo", nil];5 [sheet showinview:self];6}

Then there's going to be something like this.

iOS work notes (10)

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.