如何在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如下面的答案所示,但它似乎不了解预算属性。
答案 0 :(得分:1)
我会创建一个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];
在推送视图控制器之前设置您的预算属性