没有找到合适的产品?
联系客服协助选型:023-68661681
提供3000多款全球软件/控件产品
针对软件研发的各个阶段提供专业培训与技术咨询
根据客户需求提供定制化的软件开发服务
全球知名设计软件,显著提升设计质量
打造以经营为中心,实现生产过程透明化管理
帮助企业合理产能分配,提高资源利用率
快速打造数字化生产线,实现全流程追溯
生产过程精准追溯,满足企业合规要求
以六西格玛为理论基础,实现产品质量全数字化管理
通过大屏电子看板,实现车间透明化管理
对设备进行全生命周期管理,提高设备综合利用率
实现设备数据的实时采集与监控
利用数字化技术提升油气勘探的效率和成功率
钻井计划优化、实时监控和风险评估
提供业务洞察与决策支持实现数据驱动决策
原创|其它|编辑:郝浩|2012-08-26 22:46:14.000|阅读 593 次
概述:UITableViewCell类能够按照已有的不同标准配置显示出相应的风格内容,但有时候我们需要将内容显示为非标准的自定义模式,如何才能在iPad编程里面实现这一显示功能呢?下面就由慧都小编来为大家讲解一下具体过程:
# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>
UITableViewCell类能够按照已有的不同标准配置显示出相应的风格内容,但有时候我们需要将内容显示为非标准的自定义模式,如何才能在iPad编程里面实现这一显示功能呢?下面就由慧都小编来为大家讲解一下具体过程:
启动Xcode,选择"Create a new Xcode project",然后选择空应用程序模板,点击Next。命名为 CustomCells,然后照下图那样设置。
点击Next,选择项目的存放路径,最后点击Create。
这里需要添加两个文件,UITableViewController以及custom cell对应的xib文件。
Choose File | New > File ,然后添加一个名为 TableViewController 的UITableViewController。
如图:
对于这个controller,我们并不需要xib文件,所以直接点击Next创建。
重新创建文件,这次我们是创建一个空的 xib 文件,如下图:
点击Next,确保Device Family被设置为iPad,再点击Next,在默认路径下保存为 CellNib 文件。
接着打开 CellNib.xib 文件。在上面拖放几个 label:
这里第一个Label的字体大小是27,字体是System Italic。而其他的Label全部都是默认设置。
下一步就是为文本依然是"Label"的Label设置tag。
将第一个大字体的Label设置tag=1,然后设置Address1,Address2,Phone,Cell右边的Label的tag分别为2,3,4,5。
接着需要修改xib的File's Owner的所属类。这里选择为 TableViewController。
打开 TableViewController.h 然后添加这些属性:
#import <UIKit/UIKit.h>
@interface TableViewController : UITableViewController
@property (nonatomic, strong) NSArray *cellContent;
@property (nonatomic, strong) IBOutlet UITableViewCell *customCell;
@end
这个演示中,我们定义一个数组来记录所有cell的内容,还需要如下图那样,设置好 customCell的outlets。
现在打开TableViewController.m做出如下更改:
#import "TableViewController.h"
@interface TableViewController ()
@end
@implementation TableViewController
@synthesize cellContent, customCell;
- (NSArray *)cellContent
{
cellContent = [[NSArray alloc] initWithObjects:
[NSArray arrayWithObjects:@"Alex Ander",
@"213 4th St.", @"Apt. 17", @"555-555-5555", @"111-111-1111", nil],
[NSArray arrayWithObjects:@"Jane Doe",
@"4 Any Ave.", @"Suite 2", @"123-456-7890", @"098-765-4321", nil],
[NSArray arrayWithObjects:@"Bill Smith",
@"63 Smith Dr.", @"", @"678-765-1236", @"987-234-4987", nil],
[NSArray arrayWithObjects:@"Mike Taylor",
@"3145 Happy Ct.", @"", @"654-321-9871", @"654-385-1594", nil],
[NSArray arrayWithObjects:@"Nancy Young",
@"98 W. 98th St.", @"Apt. 3", @"951-753-9871", @"951-654-3557", nil],
nil];
return cellContent;
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
#pragma mark – Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [[self.cellContent objectAtIndex:0] count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 149.0f;
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.backgroundColor = [UIColor colorWithRed:1 green:1 blue:.75 alpha:1];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"CellNib" owner:self options:nil];
cell = self.customCell;
self.customCell = nil;
}
// Configure the cell…
UILabel *textTarget;
textTarget = (UILabel *)[cell viewWithTag:1]; //name
textTarget.text = [[self.cellContent objectAtIndex:indexPath.row] objectAtIndex:0];
textTarget = (UILabel *)[cell viewWithTag:2]; //addr1
textTarget.text = [[self.cellContent objectAtIndex:indexPath.row] objectAtIndex:1];
textTarget = (UILabel *)[cell viewWithTag:3]; //addr2
textTarget.text = [[self.cellContent objectAtIndex:indexPath.row] objectAtIndex:2];
textTarget = (UILabel *)[cell viewWithTag:4]; //phone
textTarget.text = [[self.cellContent objectAtIndex:indexPath.row] objectAtIndex:3];
textTarget = (UILabel *)[cell viewWithTag:5]; //cellPhone
textTarget.text = [[self.cellContent objectAtIndex:indexPath.row] objectAtIndex:4];
return cell;
}
#pragma mark – Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
/*
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
// …
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
*/
}
@end
#import <UIKit/UIKit.h>
#import "TableViewController.h"
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) TableViewController *tableViewController;
@property (strong, nonatomic) UINavigationController *navController;
@end
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.tableViewController = [[TableViewController alloc] initWithStyle:UITableViewStylePlain];
self.tableViewController.title = @"Table View";
self.navController = [[UINavigationController alloc]
initWithRootViewController:self.tableViewController];
[self.window addSubview:self.navController.view];
[self.window makeKeyAndVisible];
return YES;
特别注意一下tableViewController的默认cell已经被我们的自定义 cell 替代,用这种方式创建的 TableViewCell 能够包含任意控件而不仅仅只是Label与Image。运行结果如下:
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@evget.com
文章转载自:huidu面对“数字中国”建设和中国制造2025战略实施的机遇期,中车信息公司紧跟时代的步伐,以“集约化、专业化、标准化、精益化、一体化、平台化”为工作目标,大力推进信息服务、工业软件等核心产品及业务的发展。在慧都3D解决方案的实施下,清软英泰建成了多模型来源的综合轻量化显示平台、实现文件不失真的百倍压缩比、针对模型中的大模型文件,在展示平台上进行流畅展示,提升工作效率,优化了使用体验。
本站的模型资源均免费下载,登录后即可下载。模型仅供学习交流,勿做商业用途。
本站的模型资源均免费下载,登录后即可下载。模型仅供学习交流,勿做商业用途。
本站的模型资源均免费下载,登录后即可下载。模型仅供学习交流,勿做商业用途。
服务电话
重庆/ 023-68661681
华东/ 13452821722
华南/ 18100878085
华北/ 17347785263
客户支持
技术支持咨询服务
服务热线:400-700-1020
邮箱:sales@evget.com
关注我们
地址 : 重庆市九龙坡区火炬大道69号6幢
慧都科技 版权所有 Copyright 2003-
2025 渝ICP备12000582号-13 渝公网安备
50010702500608号