我需要幫助定製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