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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:02:19+00:00 2026-05-25T23:02:19+00:00

I have this problem understanding how to save data in order to have an

  • 0

I have this problem understanding how to save data in order to have an “add to favorites” function to my app.
The app has an UITableView and the data is stored in a Plist. From there
it goes into a DetailView containing an UIImageView and an UITextView.
I want to be able to bookmark the items i like and display them in a
separate view.

Here is a piece of the code to make it easier to see:

//BooksLibraryDao.h

#import <Foundation/Foundation.h>


@interface BooksLibraryDao : NSObject {
    NSString *libraryPlist;
    NSArray *libraryContent;
}

@property (nonatomic, readonly) NSString *libraryPlist;
@property (nonatomic, readonly) NSArray *libraryContent;

- (id)initWithLibraryName:(NSString *)libraryName;
- (NSDictionary *)libraryItemAtIndex:(int)index;
- (int)libraryCount;

@end


//BooksLibraryDao.m

#import "BooksLibraryDao.h"


@implementation BooksLibraryDao

@synthesize libraryContent, libraryPlist;

 - (id)initWithLibraryName:(NSString *)libraryName {
    if (self = [super init]) {
        libraryPlist = libraryName;
        libraryContent = [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] 
                                                                  pathForResource:libraryPlist ofType:@"plist"]];
    }
    return self;
}

- (NSDictionary *)libraryItemAtIndex:(int)index {
    return (libraryContent != nil && [libraryContent count] > 0 && index < [libraryContent count]) 
        ? [libraryContent objectAtIndex:index]
        : nil;
}

- (int)libraryCount {
    return (libraryContent != nil) ? [libraryContent count] : 0;
}

- (void) dealloc {
    if (libraryContent) [libraryContent release];
    [super dealloc];
}


@end


//BooksTableViewController.h

#import <UIKit/UIKit.h>
#import "BooksLibraryDao.h"
#import "BooksListingViewCell.h"
#import "BooksAppDelegate.h"


@interface BooksTableViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource> {
    IBOutlet UITableView *booksTableView;
    BooksLibraryDao *dao;

    IBOutlet BooksListingViewCell *_cell;
}


@end



//BooksTableViewController.m

#import "BooksTableViewController.h"
#import "DetailViewController.h"
#import "BooksListingViewCell.h"
#import "BooksNavController.h"

@implementation BooksTableViewController
#define CELL_HEIGHT 70.0

#pragma mark -
#pragma mark Initialization

/*
- (id)initWithStyle:(UITableViewStyle)style {
    // Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization.
    }
    return self;
}
*/


#pragma mark -
#pragma mark View lifecycle


- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.backgroundColor = [UIColor clearColor];
}


- (void)viewWillAppear:(BOOL)animated {
    dao = [[BooksLibraryDao alloc] initWithLibraryName:@"TestData"];
    self.title = @"Books";
    [self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
}

#pragma mark -
#pragma mark Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [dao libraryCount];
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"LibraryListingCell";

    BooksListingViewCell *cell = (BooksListingViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        [[NSBundle mainBundle] loadNibNamed:@"BooksListingView" owner:self options:nil];
        cell = [_cell autorelease];
        _cell = nil;
    }

    cell.titleLabel.text = [[dao libraryItemAtIndex:indexPath.row] valueForKey:@"title"];     
    cell.smallImageView.image = [UIImage imageNamed:[[dao libraryItemAtIndex:indexPath.row] valueForKey:@"smallImage"]];    
    cell.backgroundColor = [UIColor colorWithRed:9 green:9 blue:9 alpha:.7];
    cell.textLabel.backgroundColor = [UIColor clearColor];
    cell.textLabel.textColor = [UIColor colorWithRed:.1 green:.1 blue:.1 alpha:1];
    cell.selectedBackgroundView = [[[UIImageView alloc] init] autorelease];
    UIImage *selectionBackground;
    selectionBackground = [UIImage imageNamed:@"cell.png"];
    ((UIImageView *)cell.selectedBackgroundView).image = selectionBackground;
    return cell;

}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    DetailViewController *controller = [[DetailViewController alloc] 
                                        initWithBookData:[dao libraryItemAtIndex:indexPath.row]
                                        nibName:@"DetailViewController" bundle:[NSBundle mainBundle]];
    controller.title = [[dao libraryItemAtIndex:indexPath.row] valueForKey:@"title"];
    [self.navigationController pushViewController:controller animated:YES];
    [controller release];  

}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return CELL_HEIGHT;
}


#pragma mark -
#pragma mark Table view delegate


#pragma mark -
#pragma mark Memory management

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Relinquish ownership any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
    // For example: self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end


//DetailViewController.h


#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
#import <QuartzCore/QuartzCore.h>


@interface DetailViewController : UIViewController <MFMailComposeViewControllerDelegate>{
    IBOutlet UIImageView *bookImageView;
    IBOutlet UILabel *titleLabel;

    IBOutlet UITextView *authorTextView;
    IBOutlet UITextView *descriptionTextView;
    IBOutlet UILabel *message;

    NSDictionary *bookData;
}

@property (nonatomic, retain) UIImageView *bookImageView;
@property (nonatomic, retain) UILabel *titleLabel;

@property (nonatomic, retain) UITextView *descriptionTextView;
@property (nonatomic, retain) UITextView *authorTextView;
@property (nonatomic, retain) IBOutlet UILabel *message;


-(IBAction)showPicker:(id)sender;
-(void)displayComposerSheet;
-(void)launchMailAppOnDevice;
-(IBAction)showAuthor;
-(IBAction)showDesc;
-(IBAction)showImage;

- (id)initWithBookData:(NSDictionary *)data nibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil;

@end



//DetailViewController.m

#import "DetailViewController.h"



@implementation DetailViewController

@synthesize bookImageView, titleLabel, descriptionTextView, authorTextView;
@synthesize message;

- (id)initWithBookData:(NSDictionary *)data nibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        bookData = data;
    }
    return self;
}

- (void)viewDidLoad {
    bookImageView.image = [UIImage imageNamed:[bookData valueForKey:@"bookImage"]];
    titleLabel.text = [bookData valueForKey:@"title"];
    descriptionTextView.text = [bookData valueForKey:@"description"];
    authorTextView.text = [bookData valueForKey:@"author"];
    [super viewDidLoad];
}
  • 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-25T23:02:20+00:00Added an answer on May 25, 2026 at 11:02 pm

    You’ve got one of a few options for implementing favourites (really depends mostly on whether your data is persistent).

    • (A) You can add a marker for each item you display in your table,
      which marks it as a favourite – then just refer to the same data set
      but filter it for said marker. Or…

    • (B) You can create an additional list holding a copy of each item
      you want to mark as a favourite and then refer to that new list as
      your datasource.

    If your data isn’t persistent, you could still use method A and when data is refreshed only retain the marked records before you insert the new, fresh data.

    Hope that makes sense!

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

Sidebar

Related Questions

Still wresting with GWT and App Engine, and I have come to this problem:
I'm not sure how to describe this best. But I have a problem understanding
I have this problem I'm hoping someone knows the answer to. I have an
I have this problem where I open Visual Studio and the internal windows are
i have this problem to find a particular xml node l have post this
I have this problem I've been trying to tackle for a while. I have
i have this problem: ms-access could not delete and i found a potential solution
I have this problem in my ASP.NET application where I'm seeing some of my
I have this problem that my sites uses alot of ajax and when a
I have this problem containing some inequations and requirement to minimize a value. After

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.