Лучший способ выбрать ячейку для добавления в другой вид таблицы - PullRequest
0 голосов
/ 16 апреля 2011

У меня есть 2 просмотра с таблицами.Нажатие кнопки + на одной открывает другую таблицу в новом представлении, и вы выбираете ячейку, после чего следует отклонить это представление и добавить данные в ячейку в исходном представлении.

Я получил вторую таблицупросмотреть все настройки.Я должен сделать это так, когда вы выбираете ячейку, он добавляет его в избранное.Или, может быть, даже выбрать несколько ячеек, затем нажмите кнопку «Готово», а затем добавляет в избранное.Есть идеи, как это сделать?Спасибо.

РЕДАКТИРОВАТЬ:

метод addEvent только для справки:

-(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];
}

РЕДАКТИРОВАТЬ 2

Этот метод используется в view1, но его необходимо отобразить в view2, а данные выбираются из представления 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:UITableViewScrollPositionBottom animated:YES];
}

РЕДАКТИРОВАТЬ 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];
}

1 Ответ

0 голосов
/ 16 апреля 2011

В методе didSelect 2-го tableView вам необходимо обновить datasource первой таблицы, а затем либо вызвать перезагрузку при нажатии кнопки «Готово», либо использовать метод insertRowsAtIndex.

Спасибо

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...