Fast, easy, and efficient way to implement custom Tableviewcell in IOS-Pro-Test version-Elite edition

Source: Internet
Author: User

iOS7 after the new upgrade, the interface has changed greatly, the Xcode simulator removed the phone border and home button, if you want to go back to the main page, you can press and hold the Shift+comment+r key. Talk less nonsense first show the effect of UITableView set to group under the new UI:

The overall interface is more concise, and the UITableViewCell width defaults to full graphic, and rounded corners are also canceled.

The following is a procedure for customizing UITableView:

First, drag a uiimageview and two labels to the cell in the storyboard.

Then create a new MyCell class that inherits from UITableViewCell.

MyCell Code:

#import <UIKit/UIKit.h>    @interface mycell:uitableviewcell  *myimageview;   *Namelabel;   *TimeLabel;    @end  
#import"MyCell.h"@implementation MyCell-(ID) Initwithstyle: (Uitableviewcellstyle) style Reuseidentifier: (NSString *) Reuseidentifier { self=[Super Initwithstyle:style Reuseidentifier:reuseidentifier]; if(self) {//Initialization Code    }      returnSelf ; }    - (void) setselected: (BOOL) selected animated: (bool) animated {[Super setselected:selected animated:animated]; //Configure The View for the selected state}  #pragmaMark sets the cell's border width-(void) Setframe: (CGRect) frame {frame.origin.x+=Ten; Frame.size.width-= A*Ten;  [Super Setframe:frame]; } @end

Use:

Used in Uitableviewcontroller, the code is as follows:

#import"RootViewController.h"#import"MyCell.h"@interface Rootviewcontroller () @end @implementation Rootviewcontroller-(ID) Initwithstyle: (Uitableviewstyle) style { self=[Super Initwithstyle:style]; if(self) {//Custom Initialization    }      returnSelf ; }    - (void) viewdidload {[Super viewdidload]; }    - (void) didreceivememorywarning {[Super didreceivememorywarning]; //Dispose of any resources the can be recreated. }    #pragmaMark-table View Data Source-(Nsinteger) Numberofsectionsintableview: (UITableView *) TableView {return 2; }    -(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section {return 3; }    -(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath {StaticNSString *cellidentifier =@"Cell"; MyCell*cell =[TableView dequeuereusablecellwithidentifier:cellidentifier Forindexpath:indexpath]; if(cell==Nil) {Cell=[[MyCell alloc] Initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier]; } Cell.nameLabel.text=@"Wildcat"; Cell.timeLabel.text=@"2013-11-7"; returncell; }    -(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) indexpath{return   the. F; } @end

The modified effect:

Of course, if you like the cell full screen effect, you can absolutely not set the cell width ...

Fast, easy, and efficient way to implement custom Tableviewcell in IOS-Pro-Test version-Elite edition

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.