Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Nov 20, 2012, 07:56 PM   #1
troop231
macrumors 601
 
troop231's Avatar
 
Join Date: Jan 2010
Location: NSLog(@"Earth");
User editable .plist for UITableView

My app uses a .plist as it's table data source, but I want to add the ability for my users to hide and unhide certain cells that don't interest them.

I know that I can put the table into editing mode and have the user swipe to delete cells, but that isn't what I'm looking for because the user may want to restore those deleted cells at a later time, or if they mistakenly deleted a cell.

I'm looking for the checkmark type of cell marking/unmarking so the user can create a "favorites" list if you will. When the user is done being in the table "edit" mode, he/she will tap done, and the app will save what cells are to be hidden from being displayed in the table view into a settings .plist.

How could I go about doing this?

Thank you for any help offered.
__________________
iPhone 5
2013 15" rMBP 2.6

Last edited by troop231; Nov 22, 2012 at 11:49 AM.
troop231 is offline   0 Reply With Quote
Old Nov 21, 2012, 09:50 AM   #2
CodeBreaker
macrumors 6502
 
Join Date: Nov 2010
Location: Sea of Tranquility
Quote:
Originally Posted by troop231 View Post
My app uses a .plist as it's table data source, but I want to add the ability for my users to hide and unhide certain cells that don't interest them.

I know that I can put the table into editing mode and have the user swipe to delete cells, but that isn't what I'm looking for because the user may want to restore those deleted cells at a later time, or if they mistakenly deleted a cell.

I'm looking for the checkmark type of cell marking/unmarking so the user can create a "favorites" list if you will. When the user is done being in the table "edit" mode, he/she will tap done, and the app will save what cells are to be hidden from being displayed in the table view into a settings .plist.

How could I go about doing this?

Thank you for any help offered.
Pretty straight forward. Just keep a boolean for each of your table cell model objects which tells if it is to be shown or not.
__________________
.
CodeBreaker is offline   0 Reply With Quote
Old Nov 21, 2012, 10:08 AM   #3
troop231
Thread Starter
macrumors 601
 
troop231's Avatar
 
Join Date: Jan 2010
Location: NSLog(@"Earth");
Quote:
Originally Posted by CodeBreaker View Post
Pretty straight forward. Just keep a boolean for each of your table cell model objects which tells if it is to be shown or not.
By using the .hidden property for each cell?

I tried this, but my table view doesn't compensate for the empty space left by the hidden cells.

Is there a way to compensate by using
Code:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
Screenshot:

Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
    if (cell == nil) cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
    
    NSArray *documentsPath = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *PlistPath = [NSString stringWithFormat:@"%@/%@", [documentsPath objectAtIndex:0],@"Table.plist"];
    
    NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:PlistPath];
    
    NSInteger row = [indexPath row];
    
    // Set up the cell...
	NSDictionary *dictionary = [self.tableDataSource objectAtIndex:indexPath.row];
    
    if(row == 4 && ([[dict objectForKey:@"4"]isEqualToString:@"0"])){
        cell.hidden = YES;
    }
    if(row == 7 && ([[dict objectForKey:@"7"]isEqualToString:@"0"])){
        cell.hidden = YES;
    }
    
    else {
    
    tableView.separatorColor = [UIColor clearColor];
	cell.textLabel.text = [dictionary objectForKey:@"Title"];
    cell.textLabel.textColor = [UIColor whiteColor];
    cell.textLabel.highlightedTextColor = [UIColor colorWithRed:0.071 green:0.204 blue:0.565 alpha:1];
}
return cell;

}
__________________
iPhone 5
2013 15" rMBP 2.6

Last edited by troop231; Nov 21, 2012 at 10:42 AM.
troop231 is offline   0 Reply With Quote
Old Nov 21, 2012, 11:32 AM   #4
CodeBreaker
macrumors 6502
 
Join Date: Nov 2010
Location: Sea of Tranquility
Quote:
Originally Posted by troop231 View Post
By using the .hidden property for each cell?

I tried this, but my table view doesn't compensate for the empty space left by the hidden cells.

Is there a way to compensate by using
Code:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
Screenshot: Image

Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
    if (cell == nil) cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
    
    NSArray *documentsPath = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *PlistPath = [NSString stringWithFormat:@"%@/%@", [documentsPath objectAtIndex:0],@"Table.plist"];
    
    NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:PlistPath];
    
    NSInteger row = [indexPath row];
    
    // Set up the cell...
	NSDictionary *dictionary = [self.tableDataSource objectAtIndex:indexPath.row];
    
    if(row == 4 && ([[dict objectForKey:@"4"]isEqualToString:@"0"])){
        cell.hidden = YES;
    }
    if(row == 7 && ([[dict objectForKey:@"7"]isEqualToString:@"0"])){
        cell.hidden = YES;
    }
    
    else {
    
    tableView.separatorColor = [UIColor clearColor];
	cell.textLabel.text = [dictionary objectForKey:@"Title"];
    cell.textLabel.textColor = [UIColor whiteColor];
    cell.textLabel.highlightedTextColor = [UIColor colorWithRed:0.071 green:0.204 blue:0.565 alpha:1];
}
return cell;

}
You are not hiding the cell. You are hiding the contents of the cell.
What you need to do is keep only objects that are to be shown in your table's data source array.

You can do this by reading the array from the plist and filtering it so it contains only those cells which are to be shown.
__________________
.
CodeBreaker is offline   0 Reply With Quote
Old Nov 21, 2012, 12:08 PM   #5
troop231
Thread Starter
macrumors 601
 
troop231's Avatar
 
Join Date: Jan 2010
Location: NSLog(@"Earth");
Quote:
Originally Posted by CodeBreaker View Post
You are not hiding the cell. You are hiding the contents of the cell.
What you need to do is keep only objects that are to be shown in your table's data source array.

You can do this by reading the array from the plist and filtering it so it contains only those cells which are to be shown.
So if I understand correctly, I need to parse my app's table data before displaying it based upon the user's settings in the .plist? Do you know how I could do this? I'm having a hard time trying to grasp it, because my app gets it's data like this:

Code:
NSArray *tempArray = [[NSArray alloc] init];
		self.tableDataSource = tempArray;
		
		AppDelegate *AppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
		self.tableDataSource = [AppDelegate.data objectForKey:@"Rows"];
Should I use NSPredicate to search the user's settings plist and then use that to display the filtered user's table data?
__________________
iPhone 5
2013 15" rMBP 2.6

Last edited by troop231; Nov 21, 2012 at 12:20 PM.
troop231 is offline   0 Reply With Quote
Old Nov 21, 2012, 02:03 PM   #6
CodeBreaker
macrumors 6502
 
Join Date: Nov 2010
Location: Sea of Tranquility
Quote:
Originally Posted by troop231 View Post
So if I understand correctly, I need to parse my app's table data before displaying it based upon the user's settings in the .plist? Do you know how I could do this? I'm having a hard time trying to grasp it, because my app gets it's data like this:

Code:
NSArray *tempArray = [[NSArray alloc] init];
		self.tableDataSource = tempArray;
		
		AppDelegate *AppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
		self.tableDataSource = [AppDelegate.data objectForKey:@"Rows"];
Should I use NSPredicate to search the user's settings plist and then use that to display the filtered user's table data?
Exactly. You can use NSPredicate to filter the array after fetching it. Like this:

Code:
AppDelegate *AppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

// First fetch all objects
NSMutableArray *allObjects = [NSMutableArray arrayWithArray:[AppDelegate.data objectForKey:@"Rows"]];

// Create a predicate
// shouldBeHidden is the name of the boolean property
NSPredicate *aPredicate = [NSPredicate predicateWithFormat:@"shouldBeHidden == 0"];

// Filter the array
[allObjects filterUsingPredicate:aPredicate];

// Set it as the data source
self.tableDataSource = allObjects;
__________________
.
CodeBreaker is offline   0 Reply With Quote
Old Nov 21, 2012, 03:45 PM   #7
troop231
Thread Starter
macrumors 601
 
troop231's Avatar
 
Join Date: Jan 2010
Location: NSLog(@"Earth");
Quote:
Originally Posted by CodeBreaker View Post
Exactly. You can use NSPredicate to filter the array after fetching it. Like this:

Code:
AppDelegate *AppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

// First fetch all objects
NSMutableArray *allObjects = [NSMutableArray arrayWithArray:[AppDelegate.data objectForKey:@"Rows"]];

// Create a predicate
// shouldBeHidden is the name of the boolean property
NSPredicate *aPredicate = [NSPredicate predicateWithFormat:@"shouldBeHidden == 0"];

// Filter the array
[allObjects filterUsingPredicate:aPredicate];

// Set it as the data source
self.tableDataSource = allObjects;
Thank you for that!

How would I set the predicate to search for the boolean keys in a different .plist? The user's settings are stored in a different plist than the table's source.
__________________
iPhone 5
2013 15" rMBP 2.6
troop231 is offline   0 Reply With Quote
Old Nov 21, 2012, 11:15 PM   #8
CodeBreaker
macrumors 6502
 
Join Date: Nov 2010
Location: Sea of Tranquility
Quote:
Originally Posted by troop231 View Post
Thank you for that!

How would I set the predicate to search for the boolean keys in a different .plist? The user's settings are stored in a different plist than the table's source.
I didn't quite get you. But you can filter any array using the same logic. Load the array from the plist, create a mutable array with it, create the predicate and filter.
__________________
.
CodeBreaker is offline   0 Reply With Quote
Old Nov 22, 2012, 11:49 AM   #9
troop231
Thread Starter
macrumors 601
 
troop231's Avatar
 
Join Date: Jan 2010
Location: NSLog(@"Earth");
Quote:
Originally Posted by CodeBreaker View Post
I didn't quite get you. But you can filter any array using the same logic. Load the array from the plist, create a mutable array with it, create the predicate and filter.
Sorry, I probably didn't explain it right.

I have solved it now though however by using the code you created. I can't believe I overlooked it.

Thank you again sir!
__________________
iPhone 5
2013 15" rMBP 2.6
troop231 is offline   0 Reply With Quote
Old Nov 22, 2012, 11:40 PM   #10
CodeBreaker
macrumors 6502
 
Join Date: Nov 2010
Location: Sea of Tranquility
Quote:
Originally Posted by troop231 View Post
Sorry, I probably didn't explain it right.

I have solved it now though however by using the code you created. I can't believe I overlooked it.

Thank you again sir!
Happy to help
__________________
.
CodeBreaker is offline   0 Reply With Quote

Reply
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
Is Safari 7's top sites not editable? Nanasaki OS X Mavericks (10.9) 9 May 4, 2014 07:43 PM
What be the best way to create an app with a list of editable items fstigre iPhone/iPad Programming 14 Nov 24, 2012 07:52 PM
Help!!! is there a way to have the text not be editable? Afbar1114 iPhone/iPad Programming 4 Sep 10, 2012 05:02 PM
UITableView ?? Fritzables iPhone/iPad Programming 2 Jul 1, 2012 09:50 PM
Making Editable PDF Textfields/Checkmarks minichrispy Mac Applications and Mac App Store 0 Jun 1, 2012 10:01 PM

Forum Jump

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

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

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