1

ユーザーがデータを入力できるテーブルビューを作成しようとしています。新しい連絡先を作成するときに、iPhone の連絡先アプリとほぼ同じに見えるようにしたいと考えています。

以下にコードを投稿しました。

タイトル テキストの横にタイトルを入力してもらいたい、説明テキストの横に説明を入力してもらいたい、時間の横に時間を入力してもらいたい、そして場所テキストの横に、ユーザーに場所を入力してもらいたいです。

私はこれを行う方法について完全に迷っており、どんな助けも大歓迎です!

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    }

    if(indexPath.row == 0) {
        cell.textLabel.text = @"Title";
    }
    else if(indexPath.row == 1) {
        cell.textLabel.text = @"Description";
    }
    else if(indexPath.row == 2) {
            cell.textLabel.text = @"Time:";
    }
    else if(indexPath.row == 3) {
            cell.textLabel.text = @"Location:";
    }

    // Configure the cell...

    return cell;
}
4

2 に答える 2

2

UILabel と UITextfield を使用してカスタム セルを作成し、カスタム セルを再利用することができます。

cellForRowAtIndexPath:次のようにカスタムセルを使用する

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    LoginCell *cell = (LoginCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"LoginCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    }

    if (indexPath.row == 0) {
        cell.txtBox.placeholder = @"example@gmail.com";
        cell.lbllabel.text = @"Email";
    }
    else {
        cell.txtBox.placeholder = @"Required";
        cell.lbllabel.text = @"Password";
    }
    cell.Tag = indexPath.row;

    return cell;
}

テキストボックスから値を取得する

NSIndexPath *indexEmail = [NSIndexPath indexPathForRow:0 inSection:0];
LoginCell *cellEmail = (LoginCell *)[loginTableView cellForRowAtIndexPath:indexEmail];
NSString *strEmail = cellEmail.txtBox.text;

NSIndexPath *indexPassword = [NSIndexPath indexPathForRow:1 inSection:0];
LoginCell *cellPassword = (LoginCell *)[loginTableView cellForRowAtIndexPath:indexPassword];
NSString *strPassword = cellPassword.txtBox.text;

サンプルプロジェクト

于 2013-06-10T04:38:30.867 に答える
0

必要なフレームで UITextView オブジェクトのインスタンスを作成し、次の方法でセルの contentView サブビューに追加します。

[cell.contentView addSubview:textView];

お役に立てれば

于 2013-06-10T02:37:39.513 に答える