2013-06-10 4 views
1

Я пытаюсь создать табличное представление, в котором пользователь может вводить в него данные. Я хочу, чтобы он выглядел почти идентично контактному приложению на iPhone при создании нового контакта.Xcode создает текстовое поле в UITableViewController

Я разместил свой код ниже.

Рядом с текстом заголовка, я хотел бы, чтобы пользователь вводил название, рядом с текстом описания, я хотел бы, чтобы пользователь вводил описание, рядом со временем, я хотел бы, чтобы пользователь входил в время, а рядом с текстом местоположения я хотел бы, чтобы пользователь входил в местоположение.

Я полностью потерял, как это сделать, и любая помощь будет принята с благодарностью!

- (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; 
} 
+0

Почему вы не определить настроенный 'UITableViewCell'? – sunkehappy

ответ

2

Вы можете создать пользовательская ячейка с полями UILabel и UIText, затем повторно использовать пользовательскую ячейку

Использование пользовательской ячейки в 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 = @"[email protected]"; 
     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; 

Sample Project

0

Создать экземпляр объекта UITextView с рамой, что вам нужно, а затем добавить его в contentView подвид клетки следующего образом

[cell.contentView addSubview:textView]; 

Надеется, что это помогает

Смежные вопросы