您如何为 iOS 中的“音乐”应用程序中的每个轨道创建一个带有数字的 UITableView 部分,例如数字 1、2、3?提前致谢!
问问题
474 次
2 回答
2
您可以子类UITableViewCell
化并创建一个子视图 UIlabel 属性,例如......trackNumber
并在您的cellForRowAtIndex..
方法中初始化您的自定义单元格。
编辑:添加示例
//CustomCell.h
@interface CustomCell : UITableViewCell
@property(nonatomic,retain) UILabel *trackNumber;
@end
//CustomCell.m
@implementation CustomCell
@synthesize trackNumber;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
self.trackNumber = [[[UILabel alloc] initWithFrame:CGRectMake(5,5,40,40)] autorelease];
[self addSubview:self.trackNumber];
}
return self;
}
@end
#import "CustomCell.h"
在您的实现中使用它。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
CustomCell *cell = (CustomCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.trackNumber.text = [NSString stringWithFormat:@"%i",[indexPath row]];
// Configure the cell.
return cell;
}
于 2012-05-31T23:16:13.047 回答
1
创建一个自定义UITableViewCell
并用它做任何你想做的事情。在检查器中将单元格样式更改为自定义。然后画出你想要的任何东西。确保在单元格中创建的新标签和其他元素的视图部分使用 tag 属性,因为您将需要这些标签来访问任何自定义标签、按钮、文本字段,以及您在单元格中创建的任何内容。基本上在你的cellForRowAtIndexPath:
函数中,你可以使用类似的东西来拆开你的自定义单元格
UILabel *numberLabel = (UILabel *)[customCell viewWithTag:1];
于 2012-05-31T22:17:10.873 回答