iOS-related UI latest Knowledge points summary (ii)

Source: Internet
Author: User

50. Directly created tab remember to set the data source self.tableView.dataSource = self;

Wuyi-(NSString *) TableView: (UITableView *) TableView titleforfooterinsection: (nsinteger) section set footer header

-(NSString *) TableView: (UITableView *) TableView titleforheaderinsection: (nsinteger) section Set header header

53. Set the row height self.tableView.rowHeight = 100; This is also set when the height of each line is consistent (uniform row height)

-(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath, set row height separately

Self.tableView.separatorColor = [Uicolor Redcolor];

55. Set the separator line style Uitableviewcellseparatorstyle

56. The inner margin of the split line is not valid, the left side affects the position of the text in the cell, and the right side does not affect the control in the cell self.tableView.separatorInsets

57. Set head and tail for UITableView

Setting head view is only highly functional

Self.tableView.tableHeaderView = view;

Self.tableView.tableFooterView = view; Set tail view X and height are useful

Common properties of UITableViewCell.

1: Set Picture cell.imageView.image

2. Set the text caption Cell.textLabel.text

3: Set Detail description title Cell.detailTextLabel.text

60. Set the icon for the right label cell.accessorytype = Uitableviewcellaccessorydisclosureindicator; (System provided good), if your own picture can be set Cell.accessoryview = view;

Cell.backgroundcolor = [Uicolor redcolor];//cell background color

Cell.selectedbackgroundview = View;//cell When the background color is selected

63. When overriding the set method, remember to assign a value to the variable first

Self.tableview.separatorstyle= Uitableviewcellseparatorstylenone; By this sentence, you can remove the dividing line

65. Set the style of the TableView

self = [super initwithstyle:uitableviewstylegrouped];

[[UITableView alloc] initWithFrame: (CGRect) Frame style: (Uitableviewstyle) style]

Use Self.tableView.style = uitableviewstylegrouped; Error occurs, read-only property

66. Dictionary to model, generally in the most easy to get the dictionary array where the dictionary to model

Model Nesting Model: a property in the model is also a dictionary array, when the first layer of the model is KVC, the obtained value (dictionary array attribute) is converted into a model array, and the model array is saved as an attribute in the first layer model.

67. When setting the animation switch on the next page, by setting the global variable index, through different index to correlate different interface values, to achieve the interface update

68.cell can set background and background after selection

1) Background

UIView *view = [[UIView alloc]init];

View.frame = CGRectMake (20, 50, 10, 5);

View.backgroundcolor = [Uicolor Redcolor];

Cell.backgroundview = view;

2) Select Background

Cell.selectedbackgroundview = view;

69.kvc--key value encoding, you can ignore whether the property is private

Tableview.separatorcolor = [Uicolor Orangecolor];

Set the color of the divider line

71. Assigning a value to a property by means of KVC,

-(nsarray<nsstring *> *) Sectionindextitlesfortableview: (UITableView *) tableview{

Check the array to see if there is no Title property, if not, iterate through the array, take out all the values of the title property inside the array, and make the new array return

return [Self.carkindsarray valueforkey:@ "title"];

}

72. Set Alertview

Uialertview *alertview = [[Uialertview alloc]initwithtitle:@ ' modify name ' Message:nil delegate:self cancelButtonTitle:@ ' Cancel ' otherbuttontitles:@ "1", @ "2", nil];//Cancel is 0, the remaining one plus one

[Alertview show];

73. Set the input box for the Alertview

Alertview.alertviewstyle = Uialertviewstyleplaintextinput; the mode of a single input box

Uialertviewstylesecuretextinput, single encrypted input box

Uialertviewstyleloginandpasswordinput User name password entry box

Uitextfield *field = [Alertview textfieldatindex:0]; Sets the text of the input box, from the top to the following index of 0, 1, 2.

-(void) Alertview: (Uialertview *) Alertview Clickedbuttonatindex: (nsinteger) Buttonindex Ns_deprecated_ios (2_0, 9_ 0)//Input Box button Click event, by index to distinguish

75.tableView Refresh Mode

1) [Self.tableview reloaddata]; Refresh All

2) [Self.tableview Reloadrowsatindexpaths:@[self.indexpath] withrowanimation:uitableviewrowanimationright]; single row refresh

76. Accurate time-lapse tool

Dispatch_after (Dispatch_time (Dispatch_time_now, (int64_t) (1 * nsec_per_sec), Dispatch_get_main_queue (), ^{action after delay}

77. General set spacing, commonly used values, using macro definition Example: #define PADDING 10

78. Get the X, y information for an existing dimension

Cgrectgetmaxx, Cgrectgetmidy, etc.

79. Set the length of the string through the string, and the size of the font

CGRect userimageviewbounds = [string Boundingrectwithsize:cgsizemake (Maxfloat, maxfloat) options: Nsstringdrawinguseslinefragmentorigin attributes:@{nsfontattributename:[uifont systemFontOfSize: Font value]} context:nil ];

80. Latest Bullet Frame Mode

Uialertcontroller * Alertcontroller=[uialertcontroller alertcontrollerwithtitle:@ "prompt" message:@ "Congratulations on your pass." Preferredstyle:uialertcontrollerstylealert];

Uialertaction *actionok = [uialertaction actionwithtitle:@ "OK" style:uialertactionstyledefault Handler:nil];

Uialertaction *actioncancle = [uialertaction actionwithtitle:@ "Cancel" Style:uialertactionstyledefault Handler:nil];

[Alertcontroller Addaction:actionok];

[Alertcontroller addaction:actioncancle];

[Self Presentviewcontroller:alertcontroller animated:yes completion:nil];

81. General definition C becomes several special classifications, which can be defined by enumeration, the following is an example of the enumeration definition: typedef enum {

Czmessagetypeme = 0,

Czmessagetypeother

}czmessagetype;

The. Control + command+ direction varies between. m and. h

To switch

83. To add elements to an immutable group, you should first convert to a mutable array

Nsmutablearray *nmarray = Self.tgarray;

[Nmarray ADDOBJECT:TG];

Self.tgarray = Nmarray;

84. Call the proxy method or block callback, you should make a judgment before calling the method

if ([Self.delegate respondstoselector: @selector (tgfooterloadmoredata:)]) {

[Self.delegate tgfooterloadmoredata:self];

}

85.

[[[NSBundle mainbundle]loadnibnamed:@ "Cztgfooterview" Owner:nil options:nil]lastobject]; Remember to add last ZhiObject

86. Why use the frame model problem, because Heightforrow this method is executed before the Cellforrow method. The cell inside is not generated, but the row height of the cell must be returned, so the cell's height needs to be computed first through the model data, returning

NSLog (@ "%s", __func__); View method execution

(instancetype) Initwithstyle: (Uitableviewcellstyle) style usually does only two things in the C initialization method

(1. Instantiating child controls

(2. Adding child controls to the parent control does not set the data and the frame

89. Use the string to determine the Fang mode of the occupied bounds

CGRect messagebounds = [string Boundingrectwithsize:cgsizemake (Self.contentview.frame.size.width-2*padding, MAXFLOAT) Options:nsstringdrawinguseslinefragmentorigin attributes: a dictionary context:nil];

Nsdictionary * Incoming dictionary = @{nsfontattributename:[uifont Systemfontofsize:15]};

90. After the frame model is generally used, the model has a data model in it, so when lazy loading the data, we simply load the frame model and assign values through the data model properties inside the frame model, so the frame object is created with a good data model already loaded with plist. , create an array of frame models, and finally we get an array of frame models with the inclusion data model

Nsmutablearray *nmarray = [Nsmutablearray array];

2.1.2 Traversing a dictionary array

For (Nsdictionary *dict in _messageframearray) {

2.1.3 Dictionary to model and add to variable array

Czmessage *message = [Czmessage messagewithdict:dict];

Creating a Czmessageframe Model

Czmessageframe *messageframe = [[Czmessageframe alloc]init];

messageframe.message = message;

To add a frame model to a mutable array

[Nmarray Addobject:messageframe];

}

2.1.4 will be stored as a mutable array of models, assigned to the dictionary array

_messageframearray = Nmarray;

91. is also related to the use of frame model, generally used to get the height of the row when used,

-(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) indexpath{return Messageframe.rowheight}

92. Use of notifications

1). Create a notification

Nsnotification *notification = [nsnotification notificationwithname:@ "Yule" Object:sinanews userInfo:@{@ "Oscar": @ " The little plum was finally soy sauce, and got the Golden Man. "(dictionary type)}];

2). Notice of release [Notificationcenter Postnotification:notification];

3) The person who listens to the message is required to register for message monitoring

[Notificationcenter addobserver:p1 selector: @selector (shownotifaction:) Name:nil object:sinanews];

4) Listen to the message and invoke the defined method

-(void) Shownotifaction: (nsnotification *) notification{

Nsdictionary *dict = Notification.userinfo;

NSLog (@ "Recipient%@, received message%@", self.name,dict[@ "Oscar"]);

NSLog (@ "Recipient%@, received message%@", self.name,dict[@ "North Korea"]);

5). Listen for logoff messages

-(void) dealloc{

Arc non-arc, MRC

Don't forget in the non-arc

[Super Dealloc];

Destroying listener objects

[[Nsnotificationcenter defaultcenter]removeobserver:self];

}

93. Also from the use of notifications, the monitoring of the keyboard (appearing and disappearing)

[[Nsnotificationcenter defaultcenter]addobserver:self selector: @selector (changekeyboard:) Name: Uikeyboardwillshownotification Object:nil];

[[Nsnotificationcenter defaultcenter]addobserver:self selector: @selector (changekeyboard:) Name: Uikeyboardwillhidenotification Object:nil];

Methods for invoking Notifications

-(void) Changekeyboard: (nsnotification *) notification{

NSLog (@ "%@", notification);

Get userinfo Information

Nsdictionary *userinfo = notification.userinfo;//can get the frame of the keyboard and the time of the animation through the dictionary

Cgaffinetransform transForm = Self.view.transform;

Gets the height of the moved position screen-the final display of the frame's y = moved position

1. Gets the y that the keyboard eventually displays

Nsvalue *value = Userinfo[uikeyboardframeenduserinfokey];

CGRect endframe = [value cgrectvalue];

CGFloat Movey =-(SELF.VIEW.FRAME.SIZE.HEIGHT-ENDFRAME.ORIGIN.Y);

Move

TransForm = cgaffinetransformmaketranslation (0, Movey);

Perform animation move, time is keyboard animation time

[UIView Animatewithduration:[userinfo[uikeyboardanimationdurationuserinfokey] Floatvalue] animations:^{

Self.view.transform = transform;//The position of the view is moved by the position of the keyboard

}];

}

94. Get the current time

NSDate *date = [NSDate Date];

Time formatting

NSDateFormatter *format = [[NSDateFormatter alloc]init];

Formatting a formatted style

Format.dateformat = @ "hh:mm";

Convert NSDate by Style

NSString *currenttime = [format stringfromdate:date];

95. Use textfiled to click the input button, return will invoke the proxy method

Self.textField.delegate = self;

-(BOOL) Textfieldshouldreturn: (Uitextfield *) textfield{}

96. Clear TextField Information

Textfield.text = @ "";

97. How to scroll to the last line of TableView

Nsindexpath *indexpath = [Nsindexpath indexpathforrow:self.messageframearray.count-1 inSection:0];

[Self.tableview Scrolltorowatindexpath:indexpath Atscrollposition:uitableviewscrollpositionbottom Animated:YES];

98. If for a module, some exist does not exist, you can set its state is hidden, pay attention to the problem of cell reuse

99. Set the left side of the TextField with a section of the input margin

Self.textField.leftView = view;

Self.textField.leftViewMode = Uitextfieldviewmodealways;

100. In the TableView data, the display mode changes, remember to refresh TableView

iOS-related UI latest Knowledge points summary (ii)

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.