我的問題如下:我指定一個可變數組cellForRowAtIndexPath
,以便它顯示單元格中的每個數組對象。到目前爲止,單元格按預期顯示。現在我想要在第一個單元格中顯示一個UILabel
,以便其他可變數組對象將被移動到第二個單元格,第三個等等。 問題是,當我測試該條件時,確實,UILabel
顯示在第一個單元中,第一個對象。實際上,兩個元素在同一個單元格中,這不是我所期望的。我希望(條件爲真時)移動所有元素,以便它們將顯示在第二個單元格中,以便將第一個單元格留到UIlabel
。問題與cellForRowAtIndexPath數據源方法
我的相關代碼,並沒有給我什麼,我想到,是這樣的:在我的邏輯
- (UITableViewCell*)tableView:(UITableView *)_tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:@"any-cell"];
// Add and display the Cell
cell.tag = [indexPath row];
NSLog(@"cell.tag= %i",cell.tag);
//test the condition, if it's ok, then add the label to the first cell
if ([self isNoScoreLabelDisplayed] && cell.tag==0) {
UILabel *lbl=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 220, 50)];
[lbl setBackgroundColor:[UIColor greenColor]];
[cell addSubview:lbl];
}
cell.tag = [self isNoScoreLabelDisplayed]?[indexPath row]+1:[indexPath row];//here i wanted to shift the tags in case the condition is true, so that all the elements will be displayed from the second cell. But seems not doing what i want :(
//
if (indexPath.row < cellList.count) {
[cell addSubview:[cellList objectAtIndex:[indexPath row]]];//cellList is the mutable array from which i get all the elements to display in the cells
}else{
[cell addSubview:nextButton];
}
return cell;
}
我這麼想嗎? thanx提前。
據我瞭解,你想的東西像頭 - 爲什麼不能用表的headerview這個? – Pfitz 2012-07-13 07:25:58
嗨,thanx爲您的答覆。其實標題還在做其他事情,它顯示我的遊戲名稱。沒辦法使用標題:)) – Malloc 2012-07-13 07:29:26
'細胞'被創建在哪裏?你可以擴展該代碼嗎? – 2012-07-13 07:35:50