Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7728349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:41:42+00:00 2026-06-01T05:41:42+00:00

I have a very simple RootView Controller ->Detail View Controller, to display a list

  • 0

I have a very simple RootView Controller ->Detail View Controller, to display a list of core data object and show details on a selected object in the DetailViewController.
The DetailViewController is a UITableView with custom UITableViewCell that has a UITextField to allow user edits.
I am able to display the table, able to edit the text field and so on. However, I am not sure how to actually update the manage object once the user chooses the Done button or cancel the changes upon a Cancel button action.
I understand I can probably achieve this by using a EditViewController, that can be used to edit one property at a time. But, I am interested in a solution where I could support inline editing in the DetailViewController. Any suggestions would be very helpful.

Thanks,

Custom UITableView Cell code

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;

        _textField = [[UITextField alloc] initWithFrame:CGRectZero];
        [_textField setTextAlignment:UITextAlignmentLeft];
        [_textField setReturnKeyType:UIReturnKeyDone];
        [_textField setClearButtonMode:UITextFieldViewModeWhileEditing];
        [_textField setDelegate:self];
        [[self contentView] addSubview:_textField];
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void) layoutSubviews {
    [super layoutSubviews];
    CGRect contentRect = [self.contentView bounds];

    // In this example we will never be editing, but this illustrates the appropriate pattern

    if ([self isEditing]) {
        self.textLabel.frame = CGRectZero;
        self.textField.frame = CGRectMake(contentRect.origin.x + kCellLeftOffset, kCellTopOffset, contentRect.size.width - kCellLeftOffset, kCellHeight);
    }
    else {
        CGRect frame = CGRectMake(contentRect.origin.x + kCellLeftOffset, kCellTopOffset, 90, kCellHeight);
        CGRect textFrame = CGRectMake(frame.origin.x + frame.size.width + kCellLeftOffset, kCellTopOffset, 180, kCellHeight);

        self.textLabel.frame = frame;
        self.textField.frame = textFrame;
    }
}

- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
    [super setEditing:editing animated:animated];
    if (!editing)
        [_textField resignFirstResponder];
}

-(BOOL) textFieldShouldBeginEditing:(UITextField *)textField {
    return [self isEditing];
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T05:41:44+00:00Added an answer on June 1, 2026 at 5:41 am

    The text editing should really be handled in a controller rather than a view. Your custom cell is a view, the appropriate place to put the text field delegate methods would be the detail view controller.

    Here is your solution:

    Pass the managedObjectModel of your root view controller to your detail view controller as a property. Do the same with the managed object to be edited.

    In the delegate methods of your text field, update the object’s properties as appropriate

    - (void)textFieldDidEndEditing:(UITextField *)textField {
       self.managedObject.textAttribute = textField.text;
    }
    

    Finally, in your handlers of the Done and Cancel buttons, save or discard the changes:

    -(void)cancel {
       [self.managedObjectContext rollback];
       [self dismissModalViewControllerAnimated:YES];  // or pop
    }
    
    -(void)done {
       [self.managedObjectContext save:nil]; // better use proper error handling
       [self dismissModalViewControllerAnimated:YES];  // or pop
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm starting with Spring Web MVC. I have very simple controller and view, but
I have a very simple WPF application in which I am using data binding
I have very simple code: List<String> list = new ArrayList<String>(); String a = a;
I have very simple data model like this: create table Company ( id int
i have very simple problem. I need to create model, that represent element of
I have very simple select like this: SELECT * FROM table WHERE column1 IN
I have very simple window where I have 2 buttons - one for cancel,
I have a very simple problem which requires a very quick and simple solution
I have a very simple bit of script that changes the status of an
I have a very simple TCP server written in C. It runs indefinitely, waiting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.