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