根據this question(以及許多Google搜索結果),當我們處於表格視圖中,並且我們將單元格設置爲UITableViewCellStyleSubtitle
時,我們不得不調整文本在單元格標籤內部位於左側。解決方法:將textAlignment設置爲UITableViewCellStyleSubtitle的中心
但是我想行的一個(其實就是行)我表視圖的對齊中心......顯然,這是行不通的:
cell.textLabel.textAlignment = UITextAlignmentCenter;
所以我一直在想什麼,我應該做,而不是...我不知道如何幹淨地做到這一點。我能想到的最好辦法是改變這個特定的單元格,以便單元格的樣式爲UITableViewCellStyleDefault
,但我不認爲單元格屬性是可更改的。我能想到的另一種方法是對UITableViewCell
類進行子類化,但對於一個表視圖單元格來說,這看起來有點矯枉過正。你認爲我應該怎麼做才能讓最後一排對齊中心?
編輯:對於那些誰感興趣的答案:
static NSString *CellIdentifier = @"Cell";
static NSString *CellIdentifierDefault = @"CellDefault";
UITableViewCell *cell; // = [pTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (indexPath.row >= [data count])
cell = [pTableView dequeueReusableCellWithIdentifier:CellIdentifierDefault];
else
cell = [pTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil && indexPath.row < [data count]) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
else if(cell == nil && indexPath.row >= [data count]) {
//Use default style for the last cell.
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifierDefault] autorelease];
}
我想你應該只是最後一個單元格'UITableViewCellStyleDefault'。它比上面提到的任何事情都容易得多。 – Robin 2011-03-18 04:49:26
但是我需要字幕......如果我使用默認樣式,如何顯示text.detailTextLabel? – 2011-03-18 04:54:04
你必須只爲最後一行而不是任何其他行(如你在你的問題中提問) – Robin 2011-03-18 04:59:09