ラベルとTextFieldを含むTabelViewCellを使用してペン先を作成し、このセルを2行だけのTableViewにロードしています。アイテムの名前と価格を取得したいので、indexPath.row値にアクセスできるため、cellForRowAtIndexPathメソッドの各ラベルを更新しました。
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleCellIdentifier = @"AddBudgetItemCell";
SCAddBudgetItemCell *cell = (SCAddBudgetItemCell *)[tableView dequeueReusableCellWithIdentifier:simpleCellIdentifier];
if(cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:simpleCellIdentifier owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.dataTextField.delegate = self;
switch (indexPath.row)
{
case 0:
cell.titleLabel.text = @"Item";
break;
case 1:
cell.titleLabel.text = @"Price ¥";
break;
default:
break;
}
return cell;
}
ただし、作成した変数「セル」にもIndexPath.row値にもアクセスできないため、TextFieldからデータを取得する方法がわかりません。