0

I want to give textfield on tableviewcell I writen some code for that I can see textfield on cell but when i go next cell then my value is disapper and how to give on cell keyboard disapper please check this code which I writen on cell, please help me on how to disapper keyboard from cell.

I want to give textfield only at one row not at all row.

- (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] autorelease];
    }

    if ([indexPath row] == 0 && [indexPath section] == 0)
    {
    cell.textLabel.text=@"Tags";
        UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 185, 30)];
        cell.accessoryView = textField;

    }

    if ([indexPath row] == 1 && [indexPath section] == 0)
    {
         cell.textLabel.text=@"Notes";
        cell.detailTextLabel.text=app.Notes;
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
}

4 Answers 4

0

Your value disappears when your UITableView decides to requery your cell.

Look what you do then: You create a new cell with a new UITextField which - because being new - does not include any value. Your old cell (and the value with it) is lost then.

0

To dismiss keyboard your class should conform UITextFieldDelegate protocol and you should implement this method:

- (BOOL)textFieldShouldReturn:(UITextField *)txtField {
    [txtField resignFirstResponder];
    return YES;
}
0

For hiding the keyboard 'beryllium' & 'Stas' are correct. To hold the text of the textField, store the text in textFieldDidEndEditing method, like this:

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    nameString = textField.text;
}

In your cellForRowAtIndexPath method set the text of textField as textField.text = nameString after initializing the textField.

0

you can do one thing also set tag for this. and add it on cell direct without accessoryView. Use [cell addSubview:textField];to add on cell. later access it with the help of tag.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.