Zac*_*man 1 iphone uitableview iphone-sdk-3.0
- (void)viewDidLoad {
[super viewDidLoad];
[self.tableView setRowHeight:100];
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
[self.view setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
}
#pragma mark -
#pragma mark Table view data source
// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 3;
}
// 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:CGRectMake(0, 0, 320, 100) reuseIdentifier:CellIdentifier] autorelease];
// For Name/Phone:
UITextField *name = [[[UITextField alloc] initWithFrame:CGRectMake(75, 22, 200, 25)] autorelease];
[name setFont:[UIFont systemFontOfSize:14]];
[name setPlaceholder:@"John Doe"];
[name setReturnKeyType:UIReturnKeyDone];
[name setAutocapitalizationType:UITextAutocapitalizationTypeWords];
[name setAutocorrectionType:UITextAutocorrectionTypeNo];
[name setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
UITextField *phone = [[[UITextField alloc] initWithFrame:CGRectMake(75, 67, 200, 25)] autorelease];
[phone setFont:[UIFont systemFontOfSize:14]];
[phone setPlaceholder:@"0412 123 123"];
[phone setReturnKeyType:UIReturnKeyDone];
//[phone setKeyboardType:UIKeyboardTypePhonePad];
[phone setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
UIImageView *background = [[[UIImageView alloc] initWithFrame:CGRectMake(9, 11, 302, 89)] autorelease];
background.image = [UIImage imageNamed:@"book-personaldetailsbg.png"];
// Add to the View
[cell addSubview:background];
[cell addSubview:name];
[cell addSubview:phone];
// Add actions:
[name addTarget:self action:@selector(textFieldDone:) forControlEvents:UIControlEventEditingDidEndOnExit];
[phone addTarget:self action:@selector(textFieldDone:) forControlEvents:UIControlEventEditingDidEndOnExit];
}
return cell;
}
Run Code Online (Sandbox Code Playgroud)
是否有一个原因?我只设置了一些物体,所以我几乎看不出它为什么会滞后.它跳了,而不是我的手机,因为设置应用程序工作正常.
Jas*_*ien 10
由于手机呈现每一层的方式,具有许多子视图的UITableViewCells在iPhone上渲染速度很慢.
阅读本文:http://blog.atebits.com/2008/12/fast-scrolling-in-tweetie-with-uitableview/
上述帖子中的信息仍然非常重要且有用,但示例项目下载链接已被破坏(截至2011年12月8日).但是,Apple自己的表格视图文档中有平板表格单元格的示例,可以快速滚动日志.请查看:http://developer.apple.com/library/ios/#samplecode/AdvancedTableViewCells/Introduction/Intro.html
要点是:
opaque属性设置为YES显然,具有需要操作的控件的单元格不能被展平,因此我认为您只需要尝试确保您的单元格子视图不透明.
我建议的最后一件事是每次请求单元格时都不分配新对象 - 这肯定是代码中的瓶颈.您应该使用可重用单元格,并对单元格进行子类化,以便仅在第一次创建时将其字段分配并添加为子视图.后续调用应该使单元格出列并用于prepareForReuse清除其旧值.
| 归档时间: |
|
| 查看次数: |
6602 次 |
| 最近记录: |