Передача объектов с помощью didSelectRowAtIndexPath: - PullRequest
0 голосов
/ 27 марта 2012

Как мне перейти между объектами из uitableviews в мои подробные виды? Я установил условный толчок, как вы можете видеть в моем методе:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    Budget * tempBudget = [self.budgetPlan.budgets objectAtIndex:indexPath.row];

    NSString *targetViewControllerIdentifier = nil;
    if (tempBudget.hasBeenInitialized != true) {
        targetViewControllerIdentifier = @"budgetInitializerView";
        UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:targetViewControllerIdentifier];
        [self.navigationController pushViewController:vc animated:YES];

        // how do I pass the tempBudget to the pushed view?


    } else {
        targetViewControllerIdentifier = @"budgetDetailsView";
        UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:targetViewControllerIdentifier];
        [self.navigationController pushViewController:vc animated:YES];

        // how do I pass the tempBudget to the pushed view?

    }
}

У меня проблемы с UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:targetViewControllerIdentifier];

Обычно я просто устанавливаю vc.budget = tempbudget, как показано в ответе ниже, но, похоже, он не понимает свойства бюджета.

1 Ответ

1 голос
/ 27 марта 2012

Я бы создал BaseViewController с типом @property вашего объекта и отправил бы ваш объект таким образом.

// In your .h
BaseViewController : UIViewController {
}

@property (nonatomic, strong) Budget *budget;

//In your .m
@synthesize budget;

Кроме того, вы можете убрать эту строку из вашего оператора if / else, так как это то же самое:

vc.budget = tempBudget;
[self.navigationController pushViewController:vc animated:YES];

установите свойство бюджета прямо перед тем, как нажать контроллер представления

...