我想添加一個customCell,它只是讓我左對齊一個字符串,然後右對齊另一個。在之前的問題中,有人提出了以下建議,但我在使用代碼時遇到問題。 Xcode中說:RootViewController的可能不--contentView響應,並調用[自我內容查看] addSubView:項目]或[自內容查看] addSubView:等級]會崩潰我的應用程序在運行時定製單元格遇到問題UITableView
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
UILabel *rank = [[UILabel alloc] initWithFrame:CGRectMake(5, 5, 100, 20];
//Mess around with the rects, I am just merely guessing.
[rank setTag:5];
[[self contentView] addSubView:rank];
[rank release];
UILabel *item = [[UILabel alloc] initWithFrame:CGRectMake(110, 5, 220, 20];
//Important
[item setTextAlignment:UITextAlignmentRight];
[item setTag:6];
[[self contentView] addSubView:item];
[item release];
}
UILabel *rank = (UILabel *)[cell viewWithTag:5];
UILabel *item = (UILabel *)[cell viewWithTag:6];
rank = @"leftside";
item = @"rightside";
}
感謝您的任何想法
感謝這是問題,但正如你指出的滾動上/下似乎打破了一切。您使用CustomUITableViewCells描述的任何示例? – Hoofamon