我需要帮助定制UITableViewCell
定制UITabeViewCell不工作
我有建立在我使用DTO检查我的问题类型两个自定义单元格。 如果它是MCQ,则加载QuizMCQTableViewCell
或者如果它是MRQ,则加载QuizMRQTableViewCell
。
这是我的代码如下。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([[self.currentQuestionDTO type] isEqualToString:@"MCQ"])
{
QuizMCQTableViewCell *customcell = [tableView dequeueReusableCellWithIdentifier:optionCellIdentifier];
if (customcell == nil)
{
customcell = [[[QuizMCQTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:optionCellIdentifier] autorelease];
}else
{
UIImageView* MRQIV=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"checkbox.png"]];
customcell.checkBoxImgV.image = MRQIV.image;
customcell.cellTextLbl.text = @"Hello";
}
return customcell;
}
if ([[self.currentQuestionDTO type] isEqualToString:@"MRQ"])
{
QuizMRQTableViewCell *customcell = [tableView dequeueReusableCellWithIdentifier:optionCellIdentifier];
if (customcell == nil)
{
customcell = [[[QuizMRQTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:optionCellIdentifier] autorelease];
}else
{
UIImageView* MRQIV=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"radio.png"]];
customcell.radioBoxImgV.image = MRQIV.image;
customcell.cellTextLbl.text = @"Hi";
}
return customcell;
}
return nil;
}
我所面临的问题是,当 我的tableView然后加载第一个问题类型是MCQ
如此这般的第一个单元格,但没有显示任何东西,因为我写的其他循环的代码if (customcell == nil)
所以这是我的第一个问题,为什么不把文本设置为你好。 但是,当我在if循环中编写我的代码时它工作。
和我的第二个问题是, 当我为MCQ
类型的代码是在if (customcell == nil)
当我加载第二个问题类型MRQ
我的应用程序获取故障的说法以下错误
-[QuizMCQTableViewCell radioBoxImgV]: unrecognized selector sent to instance
什么,我做错了。 请帮忙。
在此先感谢..
嗨 如果我用不同的标识符仍然坠毁 我没有使用ARC不stroyboard,所有的编程 做什么可能是背后的崩溃 – Sagar
问题得到了答案, 我用不同的小区标识符,但具有相同的NSString – Sagar
谢谢全部, @AndrewMonshizadeh&danypata: - 谢谢 – Sagar