@interfaceTableViewCellViewController:UIViewController

欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

[轉]UITableViewCell的使用——自定義tableView

系統 1675 0

視圖需要我們自己去定義樣式時用到了TableViewCell組件,效果如下 ?
[轉]UITableViewCell的使用——自定義tableView視圖_第1張圖片 ?
首先創建View Based App工程,在.xib文件中拖入一個Table View,前面我們說到了,這里就不再重復,注意連接協議和兩個必須方法的實現。完成.h中代碼 ?

C代碼? ? 收藏代碼
  1. #import?<UIKit/UIKit.h> ??
  2. @interface?TableViewCellViewController?:?UIViewController??
  3. ????????????<UITableViewDelegate,UITableViewDataSource>{??
  4. ????????????????IBOutlet?UITableView?*tView;??
  5. }??
  6. @property?(nonatomic,retain)UITableView?*tView;??
  7. @end??


完成.m中代碼 ?

C代碼? ? 收藏代碼
  1. #import?"TableViewCellViewController.h" ??
  2. #import?"MyCell.h" ??
  3. @implementation?TableViewCellViewController??
  4. @synthesize?tView;??
  5. -?( void )viewDidLoad?{??
  6. ????[super?viewDidLoad];??
  7. }??
  8. -?( void )didReceiveMemoryWarning?{??
  9. ????[super?didReceiveMemoryWarning];??
  10. }??
  11. -?( void )dealloc?{??
  12. ????[tView?release];??
  13. ????[super?dealloc];??
  14. }??
  15. -(NSInteger)?tableView:(UITableView?*)tableView??
  16. ?numberOfRowsInSection:(NSInteger)section??
  17. {??
  18. ???? return ?9;??
  19. }??
  20. -?(UITableViewCell?*)tableView:(UITableView?*)tableView?cellForRowAtIndexPath:(NSIndexPath?*)indexPath??
  21. {??
  22. ???? static ?NSString?*CellIdentifier?=?@ "CustomCellIdentifier" ;??
  23. ????MyCell?*cell?=?(MyCell?*)[tableView?dequeueReusableCellWithIdentifier:CellIdentifier];??
  24. ???? if ?(cell?==?nil)?{??
  25. ????????NSArray?*array?=?[[NSBundle?mainBundle]?loadNibNamed:@ "mycell" ?owner:self?options:nil];??
  26. ????????cell?=?[array?objectAtIndex:0];??
  27. ????????[cell?setSelectionStyle:UITableViewCellSelectionStyleGray];??
  28. ????}??
  29. ????[[cell?lable]?setText:@ "31" ];??
  30. ????[[cell?lable1]?setText:@ "Raul" ];??
  31. ????[[cell?myImage]?setImage:[UIImage?imageNamed:@ "3316.jpg" ]];??
  32. ???? return ?cell;??
  33. }??
  34. -?(CGFloat)tableView:(UITableView?*)atableView?heightForRowAtIndexPath:(NSIndexPath?*)indexPath?????
  35. {?????????
  36. ???? return ?120;??
  37. }??
  38. @end??


若不需要cell則改為:?
static NSString *CellIdentifier2 = @"Cell";?
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier2];?
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier2] autorelease];?
cell.textLabel.text =@"CCCCCCCC";?
[cell.textLabel setFont:[UIFont fontWithName:@"Helvetica" size:16.0f]];?
// cell.accessoryView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sign_10x12.png"]];?
cell.selectionStyle = UITableViewCellSelectionStyleBlue;?
[cell.textLabel setTextColor:[UIColor colorWithRed:0/255.0 green:106/255.0 blue:166/255.0 alpha:1.0]];
return cell;?
下面我們新建一個類,注意subclass選擇UITableViewCell,名稱為MyCell,生成之后再創建相應的xib文件
?
[轉]UITableViewCell的使用——自定義tableView視圖_第2張圖片 ?
雙擊MyCell.xib,將Table View Cell拖入主窗口中,并且刪除原主窗口中的View圖標 ?
[轉]UITableViewCell的使用——自定義tableView視圖_第3張圖片 ?
在.h文件中完成代碼 ?

C代碼? ? 收藏代碼
  1. #import?<UIKit/UIKit.h> ??
  2. @interface?MyCell?:?UITableViewCell?{??
  3. ????IBOutlet?UILabel?*lable;??
  4. ????IBOutlet?UILabel?*lable1;??
  5. ????IBOutlet?UIImageView?*myImage;??
  6. }??
  7. @property(nonatomic,retain)?UILabel?*lable;??
  8. @property(nonatomic,retain)?UILabel?*lable1;??
  9. @property?(nonatomic,retain)?UIImageView?*myImage;??
  10. @end??


在.m中完成代碼 ?

C代碼? ? 收藏代碼
  1. #import?"MyCell.h" ??
  2. @implementation?MyCell??
  3. @synthesize?lable,lable1,myImage;??
  4. -?(id)initWithStyle:(UITableViewCellStyle)style?reuseIdentifier:(NSString?*)reuseIdentifier?{??
  5. ???? if ?((self?=?[super?initWithStyle:style?reuseIdentifier:reuseIdentifier]))?{??
  6. ???????? //?Initialization?code ??
  7. ????}??
  8. ???? return ?self;??
  9. }??
  10. -?( void )setSelected:( BOOL )selected?animated:( BOOL )animated?{??
  11. ??
  12. ????[super?setSelected:selected?animated:animated];??
  13. ??
  14. ???? //?Configure?the?view?for?the?selected?state ??
  15. }??
  16. -?( void )dealloc?{??
  17. ????[myImage?release];??
  18. ????[lable?release];??
  19. ????[super?dealloc];??
  20. }??
  21. @end??


最后我們看一下MyCell.xib中的連接,按住Ctrl拖入將要顯示區域的文字和圖片找到相應的接口即可。 (注意:是myCell和文字和圖片連接,不是file’s owner和文字和圖片連接,我又犯這個錯誤了) ?
[轉]UITableViewCell的使用——自定義tableView視圖_第4張圖片 ?

[轉]UITableViewCell的使用——自定義tableView視圖_第5張圖片

[轉]UITableViewCell的使用——自定義tableView視圖


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 日日摸夜夜添夜夜添破第一 | 亚洲人视频 | 国产一区二区三区久久久久久久久 | wankzhd | 草草免费观看视频在线 | 仇爱电视剧泰剧在线观看免费播放 | 二级黄的全免费视频 | 日日麻批的全部过程 | 国产成人精品一区二区三区视频 | 久久se精品一区精品二区 | 一级做a爰片久久毛片看看 欧美日韩精品国产一区二区 | 欧美成人在线免费观看 | 91精品一区二区综合在线 | 亚洲欧美日韩在线观看播放 | 日韩久久成人 | 麻豆av在线播放 | 欧美精品一级 | 中文字幕观看 | 锵锵锵锵锵锵锵锵锵好大好湿软件 | 在线观看av网站永久 | 日韩在线观看视频一区二区三区 | 欧美黑b | 精品久久久久久久 | 男女视频免费在线观看 | 国产一区久久 | 精品一区二区久久久久久久网站 | 国产91福利在线精品剧情尤物 | www.国产精| 一区二区三区免费在线观看 | 狠狠躁躁夜夜躁波多野结依 | 久草社区在线 | 中文字幕日韩理论在线 | 免费a级在线观看播放 | 一区二区三区四区精品 | 欧美日韩免费在线观看视频 | 三级黄色片在线免费观看 | 久操免费在线视频 | 国产免费中文字幕 | 狠狠色丁香婷婷综合久久片 | 日本理论片中文在线观看2828 | 人人澡人人爱 |