2012-04-05 4 views
0

Tab Bar 앱에서 스토리 보드가있는 RSS 리더 드릴 다운 테이블을 개발하려고합니다. 내 RootTableViewController를 파싱 된 XML로 채 웠습니다. 이제는 내 RootTableViewController의 각 행을 가리키고 선택된 셀의 데이터를 다른 DetailTableViewController로 전달하는 방법에 대한 문제가 발생했습니다.UITableView는 스토리 보드를 사용하여 UITableView 드릴 다운을 수행합니다.

이 내 코드의 일부는 XML을 구문 분석하고 RootTableViewController 채울 수 있습니다 :

스토리 보드에서
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return [stories count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *CellIdentifier = @"AdvCurrentCelly"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 
    int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1]; 
    NSString *description = [[stories objectAtIndex: storyIndex] objectForKey: @"description"]; 
    NSString *title = [[stories objectAtIndex: storyIndex] objectForKey: @"title"]; 

    //This populates the prototype cell 'AdvCurrentCelly' 
    cell.textLabel.text = title; 
    //cell.textLabel.text = date; 
    cell.detailTextLabel.text = description 

    return cell; 

} 

의 DetailTableViewController에 RootTableViewContoller 세포에서 SEGUE의 이름 ShowADVDetail

도움말이 훨씬입니다 감사합니다

답변

1

모든 유형의 데이터를 전달할 수 있지만 Title 문자열을 전달하는 방법. 그것을 myString이라고 부르 자. 첫째로 당신은 당신의 문자열을 저장하기 DetailTableViewController.h에 속성을 추가해야합니다

@property (strong, nonatomic) NSString *myString

당신은 당신이 무엇을 할 수있는 SEGUE 말할 필요 RootTableViewController에서. 다음 코드를 예로 사용하십시오.

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    // Refer to the correct segue 
    if ([[segue identifier] isEqualToString:@"ShowADVDetail"]) { 

     // Reference to destination view controller 
     DetailTableViewController *vc = [segue destinationViewController]; 

     // get the selected index 
     NSInteger selectedIndex = [[self.teamTable indexPathForSelectedRow] row]; 

     // Pass the title (from your array) to myString in DetailTableViewController: 
     vc.myString = [NSString stringWithFormat:@"%@", [[stories objectAtIndex:selectedIndex] objectForKey: @"Title"]]; 
    } 
} 
관련 문제