iOSの「音楽」アプリの各トラックの番号1、2、3のように、各行の番号を含むUITableViewのセクションをどのように作成しますか?前もって感謝します!
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;
}
Create a custom UITableViewCell
and do whatever you want with it. In the inspector change the cell style to Custom. Then draw in whatever you want. Make sure that you use the tag property on the view section of the new labels and other elements you create in the cell, because you will need those tags to access any custom labels, buttons, textfields, whatever that you make in the cell. Basically in your cellForRowAtIndexPath:
function you can pull apart your custom cell using stuff like
UILabel *numberLabel = (UILabel *)[customCell viewWithTag:1];