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 6957309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:59:04+00:00 2026-05-27T14:59:04+00:00

I’m currently developing an app that behaves like the Messages.app. The MasterViewController is the

  • 0

I’m currently developing an app that behaves like the Messages.app. The MasterViewController is the main view where it loads a table of the contact name, time and a snippet of the most recent message. When you tap a specific cell, it slides to the DetailViewController where it loads the messages I sent to the contact with the latest, complete message. Hitting the back button goes back to the MasterViewController. Tapping the rightBarButtonItem opens up a ComposeViewController (modal) where the user can compose a message to a specific contact. The difference of this app to the default Messages.app is that it has a delay timer before the message is sent. The ComposeViewController has a textfield to input the message, button to select a contact, button to pick a time delay, button to send, button to cancel the timer, and a button to dismiss the ModalViewController.

I removed the ability to send an actual SMS message entirely. I just presented the user with an alert view telling him/her that the message was sent and if he/she wants to compose a new one. Hitting Cancel will dismiss the ModalViewController and go back to the MasterViewController.

Problem is, I can’t make the rows appear on the table and also have the ability to add and remove cells in the table.

Here’s some code inside my MasterViewController’s viewDidLoad:

[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

// Delete button to delete messages
UIBarButtonItem *deleteBarButtonItem = [[UIBarButtonItem alloc] 
                                      initWithBarButtonSystemItem:UIBarButtonSystemItemTrash
                                      target:self 
                                      action:@selector(deleteText)];
self.navigationItem.leftBarButtonItem = deleteBarButtonItem;


// Compose button to go to compose messages
UIBarButtonItem *composeBarButtonItem = [[UIBarButtonItem alloc] 
                                         initWithBarButtonSystemItem:UIBarButtonSystemItemCompose
                                         target:self 
                                         action:@selector(composeText)];
self.navigationItem.rightBarButtonItem = composeBarButtonItem;

[deleteBarButtonItem release];
[composeBarButtonItem release];

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *message = [defaults objectForKey:kMessageText];
NSString *contactname = [defaults objectForKey:kContactNameText];
NSString *timestamp = [defaults objectForKey:kTimeStampText];

[messageDetails initWithObjectsAndKeys:contactname, kContactNameKey, message, kContactMsgKey, timestamp, kContactTimeKey, nil];

NSMutableArray *messageInfo = [[NSMutableArray alloc] initWithObjects:messageDetails, nil];

self.messagesList = messageInfo;

[messageInfo release];

[super viewDidLoad];

Here’s the code in cellForRowAtIndexPath:

CustomCellViewController *customCell = (CustomCellViewController *)[tableView dequeueReusableCellWithIdentifier:@"CustomCellViewController"];

if (customCell == nil)
{
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCellViewController"
                                                 owner:self 
                                               options:nil];
    for (id oneObject in nib) if ([oneObject isKindOfClass:[CustomCellViewController class]])
        customCell = (CustomCellViewController *)oneObject;
}

NSUInteger row = [indexPath row];
NSDictionary *messages = [self.messagesList objectAtIndex:row];

customCell.nameLabel.text = [messages objectForKey:kContactNameKey];
customCell.nameLabel.textColor = [UIColor whiteColor];
customCell.messageLabel.text = [messages objectForKey:kContactMsgKey];
customCell.messageLabel.textColor = [UIColor lightGrayColor];
customCell.timeLabel.text = [messages objectForKey:kContactTimeKey];
customCell.timeLabel.textColor = [UIColor blueColor];

customCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

return customCell;

Here’s the code for deleting cells:

- (void)tableView:(UITableView *)tableView commitEditingStyle(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete)
    {
    // Delete the row from the data source.        
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]withRowAnimation:UITableViewRowAnimationFade];

    [messagesList removeObjectAtIndex:indexPath.row];
    [self.tableView reloadData];
    }
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
    // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
    }   
}
  • 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-05-27T14:59:05+00:00Added an answer on May 27, 2026 at 2:59 pm

    Your final code snippet where you are creating a new instance of the master view controller is the problem.

    This is not the view controller you are looking for. Since you’ve presented the detail view controller modally, you can access the master controller via the parentViewController property of the detail controller:

    MasterViewController *master = (MasterViewController*)self.parentViewController;
    

    Other design patterns that are typically used in this situation:

    • Create the new object in your master controller and insert the row in your table before passing the new object to the detail controller for updating
    • Create a delegate protocol for the detail controller, which your master controller conforms to. Set the detail controllers delegate to the master controller when pushing it

    The latter is almost what you are doing for all practical purposes, except your detail controller knows more than it needs to about the master controller (i.e you are importing the whole master .h file rather than just knowing it conforms to a protocol).

    Regarding your data structure, I don’t understand how you expect to have multiple rows in here – you store one message in user defaults and then create an array with that message. I know you don’t intend to use defaults to store this in the end, but I would expect to see an array of dictionaries stored in defaults under a single key, and then each dictionary represents a row in your table, with the various details stored as strings in the dictionary against your message, contact name keys etc.

    You have to make a mutable version of the array returned from defaults as it always returns an immutable array.

    In your cellForRow… method you’d then get the appropriate dictionary from the array and populate the cell from it.

    When adding a new row you’d create a new dictionary to pass to your detail controller.

    When deleting a row you’d remove the relevant dictionary from the array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I would like to count the length of a string with PHP. The string
I am currently running into a problem where an element is coming back from
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into

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.