Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread Display Modes
Old Dec 4, 2012, 11:08 PM   #1
macrumors regular
Join Date: Nov 2009
Location: Irvine, CA
Table View Cell Text Help

I'm making my first app with table views and I am having trouble with the logic of it. I have a data source object with an array that contains various objects such as uiimage and nsurls pointing to word, pages, pdfs, ect. that are displayed by a uiwebview. However, before they are loaded, i want to show a table listing all the objects.
The problem is, i dont know how to display a name in the uilabel for each cell. I want the user to be able to edit the name also.

heres the code for the model
#import <Foundation/Foundation.h>

@interface CQStorageModel : NSObject<NSCoding>

@property (strong, nonatomic) NSMutableArray *dataSource;
@property (strong, nonatomic) NSURL *savingUrl;
@property (strong, nonatomic) NSURL *appSupportUrl;

- (id) initWithDataSource;
- (void) saveDataSource;

- (void) addProject: (NSMutableArray *) arry withName: (NSString *) string;
- (void) removeProjectAtIndex: (NSUInteger) index;

- (void) addObject: (id<NSCoding>) object toProjectAtIndex: (NSUInteger) index;
- (void) removeObjectAtIndex: (NSUInteger) index1 inProjectAtIndex: (NSUInteger) index2;
- (id) loadObjectAtIndex: (NSUInteger) index1 inProjectAtIndex: (NSUInteger) index2;

implementation file
#import "CQStorageModel.h"

@implementation CQStorageModel

- (void) encodeWithCoder:(NSCoder *)aCoder {
    [aCoder encodeObject:self.dataSource forKey:@"dataSource"];
    [aCoder encodeObject:self.savingUrl forKey:@"savingUrl"];
    [aCoder encodeObject:self.appSupportUrl forKey:@"APUrl"];

- (id) initWithCoder:(NSCoder *)aDecoder {
    self = [super init];
    self.dataSource = [aDecoder decodeObjectForKey:@"dataSource"];
    self.savingUrl = [aDecoder decodeObjectForKey:@"savingUrl"];
    self.appSupportUrl = [aDecoder decodeObjectForKey:@"APUrl"];
    return self;

- (id) initWithDataSource {
    self = [super init];
    if (self) {
        NSFileManager *fm = [[NSFileManager alloc]init];
        self.appSupportUrl = [fm URLForDirectory:NSApplicationSupportDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
        if (!self.appSupportUrl)
            self.appSupportUrl = [fm URLForDirectory:NSApplicationSupportDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:nil];
        self.savingUrl = [self.appSupportUrl URLByAppendingPathComponent:@"CQStorageModel.cqstm"];
        NSData *data = [[NSData alloc]initWithContentsOfURL:self.savingUrl];
        if (data)
        self = [NSKeyedUnarchiver unarchiveObjectWithData:data];
    return self;

- (void) saveDataSource {
    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:self];
    [data writeToURL:self.savingUrl atomically:NO];

- (void) addProject: (NSMutableArray *) arry withName: (NSString *) string {
    [arry insertObject:string atIndex:0];
    [self.dataSource addObject:arry];

- (void) removeProjectAtIndex:(NSUInteger)index {
    [self.dataSource removeObjectAtIndex:index];

- (void) addObject:(id<NSCoding>)object toProjectAtIndex:(NSUInteger)index {
    [[self.dataSource objectAtIndex:index] addObject:object];

- (void) removeObjectAtIndex:(NSUInteger)index1 inProjectAtIndex:(NSUInteger)index2 {
    if (index1 != 0)
        [[self.dataSource objectAtIndex:index2] removeObjectAtIndex:index1];

- (id) loadObjectAtIndex:(NSUInteger)index1 inProjectAtIndex:(NSUInteger)index2 {
    id object = [[self.dataSource objectAtIndex:index2]objectAtIndex:index1];
    return object;


Last edited by iphonedude2008; Dec 6, 2012 at 09:09 PM.
iphonedude2008 is offline   0 Reply With Quote
Old Dec 5, 2012, 08:31 AM   #2
macrumors 68000
Join Date: Aug 2007
Well, looks like you've got your storage sorted. Now you need to implement the UITableViewDataSource protocol. You could extend CQStorageModel to implement UITableViewDataSource directly, or you could create a new class which calls into your CQStorageModel.

The key methods you'll need to implement are:

– tableView:numberOfRowsInSection:
– tableView:cellForRowAtIndexPath:

Then you need to pass your UITableViewDataSource object to the table view using:

tableView.dataSource = myTableData;
Reason077 is offline   0 Reply With Quote
Old Dec 5, 2012, 09:06 AM   #3
Thread Starter
macrumors regular
Join Date: Nov 2009
Location: Irvine, CA
Ok thank you. I will do that.
iphonedude2008 is offline   0 Reply With Quote
Old Dec 5, 2012, 05:48 PM   #4
macrumors 68030
MattInOz's Avatar
Join Date: Jan 2006
Location: Sydney
Have a look on Apple's Developer site for a Sample project called Doc Interaction. It's chock full of of file/url handling goodness.
There is no such thing as "Collective Wisdom"
[ iPhone 5s, iPad Mini, 13" MacBookPro 2.7Ghz, 27"Al iMac i7, Black MacBook 13"]
MattInOz is offline   0 Reply With Quote

MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Table View Cell Separator Lines Not Showing RagingGoat iPhone/iPad Programming 8 May 20, 2013 05:43 PM
View-based table view losing selection highlight Starfox Mac Programming 1 Nov 28, 2012 01:02 AM
Find location of table view cell that calls view controller moonman239 iPhone/iPad Programming 3 Nov 24, 2012 05:31 PM
Pushing to a Detail View from a Table View Cell using Xcode Storyboard xcodeApp10 iPhone/iPad Programming 2 Sep 17, 2012 03:45 PM
Resolved: dragging text from table cell to text field straber iPhone/iPad Programming 4 Jul 11, 2012 01:27 PM

Forum Jump

All times are GMT -5. The time now is 04:01 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2015, MacRumors.com, LLC