私はUITableViewCellsでも多くの異なるUI要素を使用しています.UITableViewCellをサブクラス化し、アイテムをセルのプロパティとして独自のクラスをロールしてみませんか? 私にはうまくいくようです。
VincentsAwesomeCell.h:
@interface VincentsAwesomeCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UILabel *FooLabel;
@property (weak, nonatomic) IBOutlet UILabel *BarLabel;
@property (weak, nonatomic) IBOutlet UIImageView *ShimmyIcon;
@property (weak, nonatomic) IBOutlet UILabel *DooWopLabel;
@property (weak, nonatomic) IBOutlet UIImageView *UseIcon;
@property (weak, nonatomic) IBOutlet UILabel *TheForceLabel;
@property (weak, nonatomic) IBOutlet UIImageView *bobSledIcon;
@property (weak, nonatomic) IBOutlet UILabel *WristWatchLabel;
@property (weak, nonatomic) IBOutlet UILabel *MeatLoafLabel;
@property (weak, nonatomic) IBOutlet UILabel *SciFiLabel;
@property (weak, nonatomic) IBOutlet UILabel *CollinderLabel;
@property (weak, nonatomic) IBOutlet UILabel *RhubarbLabel;
@property (weak, nonatomic) IBOutlet UITextField *SuperTextField;
@property (weak, nonatomic) IBOutlet UIStepper *stepper;
@property (strong, nonatomic) IBOutlet UILabel *amountOfAwesomeness;
使用することを忘れないでください:
VincentsAwesomeCell.m:
- (void)prepareForReuse {
[super prepareForReuse];
// Always call this!
// Reset custom stuff
}
再利用のためにセルのプロパティをリセットします。
次に、TableViewController.m で:
- (void) viewDidLoad
{
[super viewDidLoad];
// Register the custom VincentsAwesomeCell NIB with the tableview
UINib *nib = [UINib nibWithNibName:@"VincentsAwesomeCell" bundle:nil];
[[self tableView] registerNib:nib forCellReuseIdentifier:@"VincentsAwesomeCell"];
}
に関しては
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
これを UIStepper に使用して、たとえばどのステッパーが押されたかを追跡します。
[[cell stepper]setTag:indexPath.row];
[[cell stepper]addTarget:self action:@selector(stepperChanged:) forControlEvents:UIControlEventValueChanged];
お役に立てれば!
PS
.xib ファイルを使用して、カスタム セルのレイアウトを作成します。UITableViewCell を InterFaceBuilder にドラッグしてカスタマイズするだけです! ただし、プロパティをリンクすることを忘れないでください。