I have 2 views with tables. Pressing the + button on one opens the other table up in a new view and you select the cell and it should then dismiss that view and add the data to a cell in the original view.
I got the 2nd table view all set up. I have to make it so when you select the cell, it adds it to the favorite. Or maybe even select multiple cells, then press the done button, then it adds to favorites. Any ideas on how to go about this? Thanks.
EDIT:
addEvent method just for reference:
-(void)addEvent
{
Routine *routine = (Routine *)[NSEntityDescription insertNewObjectForEntityForName:@"Routine" inManagedObjectContext:managedObjectContext];
routine.name=entered;
NSError *error = nil;
if (![managedObjectContext save:&error])
{
// Handle the error.
}
NSLog(@"%@", error);
//[eventsArray addObject:routine];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
NSInteger lastSection = [self.routineTableView numberOfSections] -1;
[self.routineTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:[self.routineTableView numberOfRowsInSection:lastSection]-1 inSection:lastSection] atScrollPosition:UITableViewScrollPositionBottom animated:YES];
}
EDIT 2
This method is in view1, but needs to be displayed in view2, and the data is selected from view 4.
-(void)addExercise
{
Exercise *exercise = (Exercise *)[NSEntityDescription insertNewObjectForEntityForName:@"Exercise" inManagedObjectContext:managedObjectContext];
exercise.name=entered;
NSError *error = nil;
if (![managedObjectContext save:&error])
{
// Handle the error.
}
NSLog(@"%@", error);
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
NSInteger lastSection = [self.routineTableView numberOfSections] -1;
[self.routineTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:[self.routineTableView numberOfRowsInSection:lastSection]-1 inSection:lastSection] atScrollPosition:UITab开发者_运维百科leViewScrollPositionBottom animated:YES];
}
EDIT 3:
-(void)addExercise
{
if (managedObjectContext == nil)
{
managedObjectContext = [(CurlAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
}
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Exercise" inManagedObjectContext:managedObjectContext];
[request setEntity:entity];
NSError *error = nil;
NSMutableArray *mutableFetchResults = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy];
if (mutableFetchResults == nil) {
// Handle the error.
}
[mutableFetchResults release];
[request release];
Exercise *exercise = (Exercise *)[NSEntityDescription insertNewObjectForEntityForName:@"Exercise" inManagedObjectContext:managedObjectContext];
exercise.name=@"Test";
if (![managedObjectContext save:&error])
{
// Handle the error.
}
NSLog(@"%@", error);
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
NSInteger lastSection = [self.tableView numberOfSections] -1;
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:[self.tableView numberOfRowsInSection:lastSection]-1 inSection:lastSection] atScrollPosition:UITableViewScrollPositionBottom animated:YES];
[tableView reloadData];
[self viewDidLoad];
}
In didSelect
method of 2nd tableView
you will need to update the datasource
of first table and then either call reload when done button is pressed or use insertRowsAtIndex
method.
Thanks,
精彩评论