在我的項目我有靜態細胞tableViews以及動態細胞tableViews。爲了定製,我設法在單元格上獲得了漸變背景(分組模式)。靜態的UITableViewCell backgroundView
它工作正常動態TableViews爲我設置cellForRowAtIndex背景視圖...根據該行的位置(頂部,底部,中部或單)。
然而,當我嘗試實現它的靜態的tableview細胞,這是行不通的。我試圖實現cellForRowAtindex ...但它崩潰。
有人有想法嗎?
更新:對於cellForRow代碼..
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UACellBackgroundView *bgw=[[UACellBackgroundView alloc]init];
if (indexPath.row==0) {
bgw.position = UACellBackgroundViewPositionTop;
cell.backgroundView=bgw;
}else if (indexPath.row==2){
bgw.position = UACellBackgroundViewPositionBottom;
cell.backgroundView=bgw;
}else {
bgw.position = UACellBackgroundViewPositionMiddle;
cell.backgroundView=bgw;
}
// cell.backgroundView=bgw;
return cell;
}
順便說一句,背景圖我是從這裏:http://code.coneybeare.net/how-to-make-custom-drawn-gradient-backgrounds這裏:http://pessoal.org/blog/2009/02/25/customizing-the-background-border-colors-of-a-uitableview/
如果有人有興趣
崩潰什麼?種類的日誌或斷點? – CodaFi
原因:「*** - [__ NSArrayI objectAtIndex:]:索引0超越界限空陣」 我覺得編譯器要我來實現數據源等。 – Marcal
錯誤的代碼。查找方法-objectAtIndex。 – CodaFi