2012-09-01 4 views
2

그래서 didSelectRowAtIndexPath 메서드가 UITableViewController에 있습니다.indexPath.row를 다른 UIViewController로 보내십시오.

는의 TableView은 있는 navigationController 의해 제어되는 의 UIViewController 간다.

내가있는 navigationController에 의해 호출 클래스에 indexPath.row을 보내 하려는

, 수있는 방법이 다른 클래스에 매개 변수를 보낼 수 있습니까?

내 응용 프로그램 방식은 다음과 같습니다

TabBarController --->있는 navigationController ---> TableViewController --->의 UIViewController

답변

0

당신은 스토리 보드를 사용하는 경우 다른

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    UITableViewCell *cell = sender; 
    // Make sure your segue name in storyboard is the same as this line 
    if ([[segue identifier] isEqualToString:@"YOUR_SEGUE_NAME_HERE"]) 
    { 
     // Get reference to the destination view controller 
     YourViewController *vc = [segue destinationViewController]; 
     NSIndexPath *indexPath = [self.tableView indexPathForCell:cell]; 

     // Pass any objects to the view controller here, like... 
     [vc setIndexPath:indexPath]; 
    } 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (indexPath.row == 0) { 
     YourViewController *vc = [[YourViewController alloc] initWithNibName:@"YourViewController" bundle:nil]; 
     [vc setIndexPath:indexPath]; 
    } 

} 
+0

저는 storyboard를 사용하고 있습니다 : 어디에서 prepareForSegue 메서드를 호출해야합니까? 난 didSelectRowAtIndexPath에서 같아요 – Wildchild89

+0

그리고 .. initWithNibName에서 호출 UIViewController는 TableViewControll이 아니므로 setIndexPath 선택기가 없습니다. – Wildchild89

+0

storyboard의 tableViewCell에서 segue를 드래그하면 prepareForSegue를 호출 할 필요가 없습니다. 당신의 viewController, 당신은 @ "YOUR_SEGUE_NAME_HERE"라고 이름을 짓고, 그 후에 사용자 탭 셀을 사용할 때 prepareForSegue 메서드가 호출됩니다. 데이터를 전달하려면 UIViewController에 @property가 있어야합니다 (예 : NSIndexPath 또는 NSInteger 행). set property [vc setRow : indexPath.row]를 전달하면됩니다. – mientus

관련 문제