[英]Multiple custom UITableViewCell using the same TableViewCell prototype
我想看看在iOS7中有哪些選擇。 我在UITableViewController
有一個標識符為TableViewCell_RightDetailID
的TableViewCell原型。 我還有另外兩個想要使用此原型的自定義tableviewcell類。
有關如何執行此操作的任何想法? 不確定是否可能?
@interface TableViewCellA : UITableViewCell
@interface TableViewCellB : UITableViewCell
我認為這樣的事情應該起作用:
TableViewController.m
#import "TVC.h"
#import "TableViewCellA.h"
#import "TableViewCellB.h"
@implementation TVC
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 2;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row == 0)
{
TableViewCellA *cell = [tableView dequeueReusableCellWithIdentifier:@"TableViewCell_RightDetailID"];
// title, detaillabel etc
return cell;
}
else
{
TableViewCellB *cell = [tableView dequeueReusableCellWithIdentifier:@"TableViewCell_RightDetailID"];
// TO DO
return cell;
}
}
@end
由於單元的類別是在情節提要中的原型中設置的,因此除非在情節提要中復制原型(並使用不同的重用標識符),否則無法進行更改。
實際上,這可能是用於在代碼中進行布局並通過[UITableView registerClass:forCellReuseIdentifier:]
注冊所有三個類的參數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.