0

ラベルと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からデータを取得する方法がわかりません。

4

1 に答える 1

0

As I understand it you have two options. If Inside your SCAddBudgetItemCell you have a property containing the string of the textfield then probably you can access it from your viewcontroller by doing something like cell.yourtextfield.text (where yourtexfield is the UITextView inside your SCAddBudgetItemCell.

The other option is to make the view controller respond to the UITextFieldDelegate and store the string as the user edits it by implementing the delegate methods

- (void)textFieldDidBeginEditing:(UITextField *)textField{
    //Whenever people start editing your textfield
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
     //
return YES;
}
-(void)textFieldDidEndEditing:(UITextField *)textField
{
    //This is obvious. Whenever they end
}
于 2013-02-25T09:05:39.330 に答える