Image Adaptive height within the Cell of the UITableViewCell

Source: Internet
Author: User

1 #import "MainViewController.h"2 3 #import "MyCell.h"4 5 @interfaceMainviewcontroller () <uitableviewdelegate, uitableviewdatasource>;6 7 8 9 @endTen  One  A @implementationMainviewcontroller -  -  the- (ID) Initwithnibname: (NSString *) Nibnameornil Bundle: (NSBundle *) Nibbundleornil -  - { -  +Self =[Super Initwithnibname:nibnameornil Bundle:nibbundleornil]; -  +     if(self) { A  at         //Custom Initialization -  -          -  -Self.array =[Nsmutablearray array]; -  in          -  to          for(inti =0; I < -; i++) { +  -UIImage *image = [UIImage imagenamed:[nsstring stringWithFormat:@"%d.jpg", I]]; the  * [Self.array addobject:image]; $ Panax Notoginseng         } -  the     } +  A     returnSelf ; the  + } -  $  $- (void) Viewdidload -  - { the  - [Super Viewdidload];Wuyi  the     //Do any additional setup after loading the view. -  Wu      -  AboutSelf.tableview = [[UITableView alloc] Initwithframe:cgrectmake (0,0, the,480) Style:uitableviewstyleplain]; $  -Self.tableview.Delegate=Self ; -  -Self.tableView.dataSource =Self ; A  +      the  - [Self.view AddSubview:self.tableView]; $  the [Self.tableview release]; the  the } the  -  in-(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) Indexpath the  the { About  the     //set the height of each cell in the protocol method of the TableView the  the      +  -UIImage *image =[Self.array ObjectAtIndex:indexPath.row]; the Bayi      the  the     //Cell height = Cell width * height of picture/width of picture -  -CGFloat cellheight = tableView.bounds.size.width * Image.size.height/Image.size.width; the  the     returnCellheight; the  the      -  the } the  the 94-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) section the  the { the 98NSLog (@"%d", self.array.count); About  -     return[Self.array Count];101 102 }103 104-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath the 106 {107 108     StaticNSString *cellid =@"Reuse";109  theMyCell *cell =[TableView dequeuereusablecellwithidentifier:cellid];111  the     if(Cell = =Nil) {113  theCell =[[[ MyCell alloc] Initwithstyle:uitableviewcellstyledefault reuseidentifier:cellid]autorelease]; the  the     }117 118UIImage *image =[Self.array ObjectAtIndex:indexPath.row];119  -Cell.myImageView.image =image;121 122     returncell;123 124 } the 126- (void) didreceivememorywarning127  - {129  the [Super didreceivememorywarning];131  the     //Dispose of any resources the can be recreated.133 134}

Image Adaptive height within the Cell of the UITableViewCell

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.