Contacts xib files and storyboard mixed programming

Source: Internet
Author: User

The Address book implemented in storyboard now replaces the code with the interface

Add a new Xib file

1 #pragmaMark creates a line with xib and adds text and avatar2-(UIView *) Createrowview3 {4     //0. Load the Rowview file, create an objects array to wrap all controls in order to return xib = The nib app automatically generates XIB files when packaged5Nsarray *views = [[NSBundle mainbundle] loadnibnamed:@"Rowview"owner:self Options:nil];6     //1. Remove a line view7UIView *rowviews = views[0];8     //2. Set the Avatar9UIButton *imgbtn = (UIButton *) [Rowviews Viewwithtag:1];TenNSString *names = [NSString stringWithFormat:@"0%d.jpg", Arc4random_uniform (9)]; One     //2.1 Set Avatar button background graph get avatar randomly A [imgbtn setimage:[uiimage imagenamed:names] forstate:uicontrolstatenormal]; -     //2.2 Add Avatar Click to listen - [imgbtn addtarget:self Action: @selector (Iconclick:) forcontrolevents:uicontroleventtouchupinside]; the     //3. Settings Description -UILabel *lab = (UILabel *) [Rowviews Viewwithtag:2]; -     //3.1 Random access to descriptive information -Lab.text =_allnames[arc4random_uniform ((int) _allnames.count)]; +     //4. Set the Delete button -UIButton *delbtn = (UIButton *) [Rowviews Viewwithtag:3]; +     //4.1 Add Delete Click to listen A [delbtn addtarget:self Action: @selector (Delclick:) forcontrolevents:uicontroleventtouchupinside]; at     returnrowviews; -}

The second way to remove the added listener is to connect (to change the controller environment to be consistent)

Change the owner file associated class file from the Xib form the name matches the name of the storyboard.h.

To change the load resolution Xib load method, change the Owner property to the current form: self

1       // 0. Load the Rowview file, create an objects array to wrap all controls in order to return xib = The nib app automatically generates XIB files when packaged 2      Nsarray *views = [[NSBundle mainbundle] loadnibnamed:@ "rowview" owner: Self Options:nil];

Contacts xib files and storyboard mixed programming

Related Article

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.