|
|
#1 |
|
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.
__________________
My iOS apps: MyTradeshow , Outdoor Rules & Regulations iPhone 5 MBP 15" 2.3 i7 HR-AG
Last edited by troop231; Nov 22, 2012 at 11:49 AM. |
|
|
|
0
|
|
|
#2 | |
|
Quote:
__________________
. |
||
|
|
0
|
|
|
#3 | |
|
Quote:
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 ![]() 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;
}
__________________
My iOS apps: MyTradeshow , Outdoor Rules & Regulations iPhone 5 MBP 15" 2.3 i7 HR-AG
Last edited by troop231; Nov 21, 2012 at 10:42 AM. |
||
|
|
0
|
|
|
#4 | |
|
Quote:
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.
__________________
. |
||
|
|
0
|
|
|
#5 | |
|
Quote:
Code:
NSArray *tempArray = [[NSArray alloc] init]; self.tableDataSource = tempArray; AppDelegate *AppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; self.tableDataSource = [AppDelegate.data objectForKey:@"Rows"];
__________________
My iOS apps: MyTradeshow , Outdoor Rules & Regulations iPhone 5 MBP 15" 2.3 i7 HR-AG
Last edited by troop231; Nov 21, 2012 at 12:20 PM. |
||
|
|
0
|
|
|
#6 | |
|
Quote:
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;
__________________
. |
||
|
|
0
|
|
|
#7 | |
|
Quote:
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.
__________________
My iOS apps: MyTradeshow , Outdoor Rules & Regulations iPhone 5 MBP 15" 2.3 i7 HR-AG
|
||
|
|
0
|
|
|
#8 |
|
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.
__________________
. |
|
|
|
0
|
|
|
#9 | |
|
Quote:
I have solved it now though however by using the code you created. I can't believe I overlooked it. Thank you again sir!
__________________
My iOS apps: MyTradeshow , Outdoor Rules & Regulations iPhone 5 MBP 15" 2.3 i7 HR-AG
|
||
|
|
0
|
|
|
#10 | |
|
Quote:
__________________
. |
||
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 09:21 AM.




iPhone 5



Linear Mode
