2012-03-27 7 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

수 당신은 "예산 재산을 이해하지 못하는 것"에 대해 자세히 설명합니까? 컴파일러 경고? 추락? 새보기에 아무 것도 표시되지 않습니까? –

+0

새보기에 아무것도 표시되지 않습니다. 그것은 통과하지 않는 것 같습니다. – iggy2012

답변

1

@property 유형의 개체가있는 BaseViewController을 만들고 그런 식으로 개체를 보냅니다. 또한

// In your .h 
BaseViewController : UIViewController { 
} 

@property (nonatomic, strong) Budget *budget; 

//In your .m 
@synthesize budget; 

, 당신은 당신이 같은 일 이후/else 문이 경우에서이 줄을 이동할 수 있습니다

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

예산 속성을 설정하면 밀어 직전에 뷰 컨트롤러

+0

vc.Budget = tempBudget을 수행하면 어떤 이유로 든 데이터를 전달하지 않는 것처럼 보입니다. – iggy2012

+0

또한 로컬 변수이므로 vc.budget = tempBudget을 이동할 수 없습니다. – iggy2012

+0

클래스에서 만든 속성이 있다면 가장 확실하게 지역 변수를 전달할 수 있습니다. –

관련 문제