xcode 自定义 UITableView

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7592960/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 22:03:13  来源:igfitidea点击:

Custom UITableView

iphoneobjective-cxcodeios4xcode4

提问by user964627

I have successfully made a iPhone app that uses a UITableView. I would like to start adding some life to the app. How do I customize the table? For example, change the height of the cells, add custom images to the cell, color, and So on....

我已经成功地制作了一个使用 UITableView 的 iPhone 应用程序。我想开始为应用程序添加一些生命。如何自定义表格?比如改变单元格的高度,给单元格添加自定义图片,颜色等等....

Any good advice?

有什么好的建议吗?

回答by Rajat

UITableViewCell *cell = [tv dequeueReusableCellWithIdentifier:CellIdentifier];

if(cell == nil)
{

    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    UILabel *label;

    label = [[[UILabel alloc] initWithFrame:CGRectMake(5, 0.5, 240.0, 25.0)] autorelease];
    label.tag = WHAT_TAG;
    label.font = [UIFont boldSystemFontOfSize:14.0];
    label.textAlignment = UITextAlignmentLeft;
    label.textColor = [UIColor blueColor];
    label.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight;
    label.backgroundColor = [UIColor clearColor];
    [cell.contentView addSubview:label];

}

Just try this use a label to overwrite the table cell and by customizing the label you can customize the tabel cell. Hope it helps...

只需尝试使用标签覆盖表格单元格,通过自定义标签,您可以自定义表格单元格。希望能帮助到你...

回答by user387184

You may also check Apples own sample code.

您也可以查看 Apple 自己的示例代码。

Especially the tableViewSuite is very nice and demonstrates all the main features in a clear understandable way.

尤其是 tableViewSuite 非常好,并且以清晰易懂的方式展示了所有主要功能。

It also shows best practice from Apple...

它还展示了 Apple 的最佳实践...

http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UITableView_Class/Reference/Reference.html

http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UITableView_Class/Reference/Reference.html