Hey all,
I am developing an app with core data which allows the user to add and switch between multiple user "accounts". The main functionality of the app is as such:
Right now, I have only been able to show/hide cell text labelling based on this principle (the table view is still populated by every event, just only the events that match the user have their labels - see photo). I want to be able to only show the events that match, without any gaps in between.
My code for the table view:
Any help appreciated.
I am developing an app with core data which allows the user to add and switch between multiple user "accounts". The main functionality of the app is as such:
- The user creates a new "event" and certain properties of the event are stored in an entity. One of the properties is "user" which is stored in the user attribute. This records whatever user account is selected at the current time in the app
- The user can then view the events they have created in a table view. But only the events which were created under the same account as the current account are to be shown.
Right now, I have only been able to show/hide cell text labelling based on this principle (the table view is still populated by every event, just only the events that match the user have their labels - see photo). I want to be able to only show the events that match, without any gaps in between.
My code for the table view:
Code:
- (NSManagedObjectContext *)managedObjectContext
{
NSManagedObjectContext *context = nil;
id delegate = [[UIApplication sharedApplication] delegate];
if ([delegate performSelector:@selector(managedObjectContext)]) {
context = [delegate managedObjectContext];
}
return context;
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
NSManagedObjectContext *managedObjectContext = [self managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"Device"];
self.devices = [[managedObjectContext executeFetchRequest:fetchRequest error:nil] mutableCopy];
[self.tableView reloadData];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return self.devices.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
NSManagedObject *device = [self.devices objectAtIndex:indexPath.row];
NSString *comparison = [NSString stringWithFormat:@"%@", [device valueForKey:@"user"]];
if ([userSelection isEqualToString:comparison]){
[cell.textLabel setText:[NSString stringWithFormat:@"%@ %@ %@ %@", [device valueForKey:@"goals"], [device valueForKey:@"passes"], [device valueForKey:@"shots"], [device valueForKey:@"date"]]];
}
return cell;
}
Any help appreciated.