2012-07-17 5 views
0

이것은 아마도 내가 이해하지 못하는 간단한 문제 일 것이라고 생각하지만 시간을 많이 썼기 때문에 내 작업을 고수하고 있습니다.UITableViewController를 밀고 데이터를 필터링/다시로드

"topics"의 4 행을 표시하는 UITableViewController가 있습니다. 하나를 만지면, 그것은 내 UITableViewController 클래스의 인스턴스를 만들고, 데이터 소스 배열을 "부차 뷰"의 배열로 설정하고 컨트롤러를 nav 스택에 푸시합니다. 10 개의 행으로 "모든"주제 페이지로 이동하면 결과를 필터링 할 수있는 분할 된 컨트롤이 있습니다. 배열을 성공적으로 필터링 할 수 있지만 self.topicsDataSource에 할당하고 [self.tableView reloadData]를 호출하면 아무 일도 일어나지 않습니다. 대리자는 numberOfSections 및 numberOfRowsInSection 메서드를 사용하지만 cellForRowAtIndexPath 메서드는 그렇지 않습니다. 내비게이션 뒤로 버튼을 누르면 이전 테이블이 맨 위 테이블에서 필 터링 된 결과가됩니다.

여기 내가 생각하는 바가 있습니다. 1. 이전 테이블의 데이터 소스를 실제로 변경하고 있으며 해당 테이블에서 self.tableView.reloadData가 호출되고 있습니다. 2. 다시로드중인 tableview가 표시되지 않으므로 cellForRowAtIndexPath가 호출되지 않습니다.

여기 내가 테이블 뷰를 푸시하는 것을 인스턴스화합니다.

- (void)segControlChanged:(UISegmentedControl *)sender 
{ 
    self.allTopics = [NSMutableArray arrayWithArray:[DataManager getTopicsAtEndOfTree]]; 
    if (sender.selectedSegmentIndex == 1) { 
     NSPredicate *pred = [NSPredicate predicateWithFormat:@"type == 2"]; 
     NSMutableArray *mArr = [[NSMutableArray alloc] initWithArray:[self.allTopics filteredArrayUsingPredicate:pred]]; 
     self.topicsDataSource = mArr; 
    } 
    else if (sender.selectedSegmentIndex == 2) { 
     NSPredicate *pred = [NSPredicate predicateWithFormat:@"type == 1"]; 
     NSMutableArray *mArr = [[NSMutableArray alloc] initWithArray:[self.allTopics filteredArrayUsingPredicate:pred]]; 
     self.topicsDataSource = mArr; 
    } 
    else { 
     NSMutableArray *mArr = [[NSMutableArray alloc] initWithArray:[DataManager getTopicsAtEndOfTree]]; 
     self.topicsDataSource = mArr; 
    } 
    [self.tableView reloadData]; 

} 

어떤 도움을 주시면 감사하겠습니다 : 나는 데이터를 필터링하고있는 tableView를 다시로드하고 곳이 클래스는 여기

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    NSNumber *idtopic = [[self.topicsDataSource objectAtIndex:indexPath.row] idtopic]; 
    NSArray *subtopics = [DataManager getSubtopicsForTopic:idtopic]; 

    if ([subtopics count] > 0) { 
     TopicsViewController *topicsVC = [[TopicsViewController alloc ] init]; 
     topicsVC.tableView.rowHeight = 106; 
     topicsVC.parentTopicId = idtopic; 
     topicsVC.topicsDataSource = [NSMutableArray arrayWithArray:subtopics]; 
     topicsVC.diseaseStateId = self.diseaseStateId; 
     topicsVC.title = [[self.topicsDataSource objectAtIndex:indexPath.row] topic]; 
     [self.navigationController pushViewController:topicsVC animated:YES]; 
    } 

    else if (![[self.topicsDataSource objectAtIndex:indexPath.row] topic]) { 
     //all topics was selected 
     TopicsViewController *topicsVC = [[TopicsViewController alloc] initWithNibName:nil bundle:nil]; 
     topicsVC.tableView.rowHeight = 106; 
     NSMutableArray *mArray = [[NSMutableArray alloc] initWithArray:[DataManager getTopicsAtEndOfTree]]; 
     topicsVC.allTopics = mArray; 
     topicsVC.topicsDataSource = topicsVC.allTopics; 
     topicsVC.diseaseStateId = self.diseaseStateId; 
     topicsVC.parentTopicId = [NSNumber numberWithInt:100]; 

     UISegmentedControl *segControl = [[UISegmentedControl alloc] initWithItems:[[NSArray alloc] initWithObjects:@"All", @"Speaker Direct", @"Live Meeting", nil]]; 
     [segControl addTarget:self action:@selector(segControlChanged:) forControlEvents:UIControlEventValueChanged]; 
     [segControl setSegmentedControlStyle:UISegmentedControlStyleBar]; 
     [segControl setSelectedSegmentIndex:0]; 
     topicsVC.navigationItem.titleView = segControl; 
     topicsVC.tableView.dataSource = topicsVC; 
     [self.navigationController pushViewController:topicsVC animated:YES]; 
    }.... 

TopicsViewController

라고하고있다. 감사!

답변

0
- (void)segControlChanged:(UISegmentedControl *)sender 
{ 
    self.allTopics = [NSMutableArray arrayWithArray:[DataManager getTopicsAtEndOfTree]]; 
    if (sender.selectedSegmentIndex == 1) { 
     NSPredicate *pred = [NSPredicate predicateWithFormat:@"type == 2"]; 
     NSMutableArray *mArr = [[NSMutableArray alloc] initWithArray:[self.allTopics filteredArrayUsingPredicate:pred]]; 
     self.topicsDataSource = mArr; 
    } 
    else if (sender.selectedSegmentIndex == 2) { 
     NSPredicate *pred = [NSPredicate predicateWithFormat:@"type == 1"]; 
     NSMutableArray *mArr = [[NSMutableArray alloc] initWithArray:[self.allTopics filteredArrayUsingPredicate:pred]]; 
     self.topicsDataSource = mArr; 
    } 
    else { 
     NSMutableArray *mArr = [[NSMutableArray alloc] initWithArray:[DataManager getTopicsAtEndOfTree]]; 
     self.topicsDataSource = mArr; 
    } 

[tableView reloadData]; // 

} 
0

그것은 무슨 일이 일어나고 있는지 당신의 질문은 무엇을 이야기하는 것은 매우 어렵습니다 - 나는 훨씬 적은 임의의 코드를 더 설명하고, 더 확실한 질문 (또한 더 나은 형식)로 질문을 다음 번에 건의 할 것입니다. 어쨌든.

내가 알 수있는 것처럼 self은 여전히 ​​원래보기 컨트롤러를 나타냅니다. 난 당신의 코드에서 오는 어떤 클래스 모르겠지만 당신이 원하는 경우에 이것은 당신은/등 사용자 정의 클래스 내부

  • , 정의 TopicsViewController
  • 푸시에 대한 사용자 정의 클래스를 작성

    1. 에 필요한 작업 데이터 소스, 다시로드 등
    2. 전화주세요 전화 사용자 정의 클래스의 tableViewreloadData 방법
    3. 사용자 정의 클래스의 내부 변경 데이터 소스 방법.

    요점은 모든 작업이 사용자 지정 테이블 뷰 데이터 컨트롤러의 클래스 내부에서 발생하는지 확인하는 것입니다.

  • 관련 문제