为tableView注册笔尖名称
static NSString *cellIdentifier = @"cell";
if (tableView ==tableview1)
{
ContactCustom *cell1=(ContactCustom *) [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell1 == nil)
{
[[NSBundle mainBundle] loadNibNamed:@"ContactCustom" owner:self options:nil];
cell1 = contactCustom;
}
}
如何在拨打cellForRowAtIndex
方法之前在viewDidLoad
方法中注册笔尖名称?为tableView注册笔尖名称
static NSString *cellIdentifier = @"cell";
if (tableView ==tableview1)
{
ContactCustom *cell1=(ContactCustom *) [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell1 == nil)
{
cell1 = [tableview dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
}
}
苹果的UITableView提供寄存器笔尖方法IOS 5 后请检查类别参考 http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableView_Class/Reference/Reference.html
例:
In view did load you can register nib for UITableView like below
[tableView registerNib:[UINib nibWithNibName:@"nibName" bundle:nil] forCellReuseIdentifier:@"identifienName"];
In cellForRowAtIndexPath
cell = [tableView dequeueReusableCellWithIdentifier:@"identifienName"];
出现error.How如何更改此代码的tableView与customCell – user2134883 2013-03-12 12:39:48
您收到哪个错误? – Narayana 2013-03-12 12:44:07
***由于未捕获的异常'NSUnknownKeyException',原因:'[
// First of all Declare an IBOutlet for your customCell in Your View Controller
IBOutlet ScoreCell *scoreCell;
// Synthesize it.
// Assign your view controller class to File Owner of your custom cell (Eg. File Owner of ScoreCell.xib)
// Then Assign Reference Outlet of ScoreCell.xib with Object 'scoreCell'
// Finally Create your custom Cell as follow :
ScoreCell *cell = (ScoreCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:nibName owner:self options:nil];
cell = [nib objectAtIndex:0];
}
寄存器包含与表的单元格的笔尖对象在指定的标识符下查看。
- (void)registerNib:(UINib *)nib forCellReuseIdentifier:(NSString *)identifier
Parameters
笔尖 甲笔尖对象,指定笔尖文件以用于创建细胞。该参数不能为零。 标识符 该单元的重用标识符。该参数不能为零,也不能是空字符串。
这doc可以帮助你很多
你能举个例子吗? – user2134883 2013-03-12 13:09:39
(void)viewDidLoad
{
[super viewDidLoad];
UINib *cellNib = [UINib nibWithNibName:@"cell" bundle:nil];
[self.tableView registerNib:cellNib forCellReuseIdentifier:@"cell"];
}
这是正确的答案,经过数小时的相同问题的努力和尝试其他所有提到这最终解决了我的问题。这样做后,您可以从cellForRowAtIndex方法中删除“if”语句 – Chris 2014-01-31 08:56:18
在这里看到:http://mrmaksimize.com/Custom-UITableViewCell-With-NIB/
- (void)viewDidLoad
{
[super viewDidLoad];
[self.tableView registerNib:[UINib nibWithNibName:@"EXCustomCell"
bundle:[NSBundle mainBundle]]
forCellReuseIdentifier:@"CustomCellReuseID"];
}
在后面的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CustomCellReuseID";
EXCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
[cell.cellItemImage setImage:[UIImage imageNamed:@"glyphicons_428_podium"]];
[cell.cellItemLabel setText = @"Mr Burns."];
return cell;
}
越来越无法识别的选择发送到实例错误 – user2134883 2013-03-12 12:26:50
你检查xib与类正确连接,标识符为p roper set in xib and use below code cell = [tableview dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath]; – Wish 2013-03-12 12:36:28
它应该是ContactCustom类中的Identifier属性中的单元格 – user2134883 2013-03-12 12:43:39