我想添加一个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