2012-03-27 69 views
-2

如何将对象从uitableviews传递到我的详细视图?我已经设置了一个条件推,你可以在我的方法,请参阅:使用didSelectRowAtIndexPath传递对象:

-(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

灿你详细说明“似乎不了解预算财产”?编译器警告?崩溃?新视图上没有显示任何内容? – 2012-03-27 18:09:50

+0

新视图中不显示任何内容。它似乎没有通过。 – iggy2012 2012-03-27 20:52:30

回答

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

设定预算属性你推右前视图控制器

+0

如果我做vc.Budget = tempBudget,它似乎并没有传递数据。 – iggy2012 2012-03-27 18:05:50

+0

另外,我不能移动vc.budget = tempBudget,因为它是一个局部变量。 – iggy2012 2012-03-27 18:06:07

+0

如果你有一个在Class中创建的属性,你肯定可以传递一个局部变量给它。 – 2012-03-27 18:19:34