2014-09-09 5 views
0

내 UITableViewCell이 textLabel에 적절한 텍스트를 표시하려고 시도했지만 현재 텍스트가 표시되고 있지 않습니다. NSLOG 배열에 데이터가 있는지 확인하려고 시도했다. 배열을 살펴보고 내가 가져온 Core Data 엔티티의 각 항목에서 텍스트를 인쇄하고 원하는 텍스트를 다시 가져 오려고했습니다. 셀에있는 모든 정보를 표시 할 때 아무 일도 일어나지 않습니다. 또한 cellForRowAtIndexPath 메서드도 호출되지 않는 것을 알 수 있습니다.UITableViewCell textLabel이 텍스트를 표시하지 않습니다.

UIAlertView 단추에서보기가 처음 전환되는 방식은 다음과 같습니다.

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ 
    NSString *title = [alertView buttonTitleAtIndex:buttonIndex]; 

    if ([title isEqualToString:@"Corp"]){ 
     DeckBuilderTableViewController *deckBuilder = [[DeckBuilderTableViewController alloc]init]; 
     [deckBuilder fetchCorpCards]; 
     [self performSegueWithIdentifier:@"deckBuilder" sender:self]; 
    } 

    if ([title isEqualToString:@"Runner"]){ 
     DeckBuilderTableViewController *deckBuilder = [[DeckBuilderTableViewController alloc]init]; 
     [deckBuilder fetchRunnerCards]; 
     [self performSegueWithIdentifier:@"deckBuilder" sender:self]; 
    } 
} 

여기에 cellForRowAtIndexPath 메소드가 있습니다.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSLog(@"cellForRowAtIndexPath called"); 
    NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 

    // Configure the cell... 
    if (self.corpCardsSelected == YES){ 
     CorpCard *corpCards = [self.datasource objectAtIndex:indexPath.row]; 
     cell.textLabel.text = corpCards.title; 
    } 

    if (self.runnerCardsSelected == YES){ 
     RunnerCard *runnerCards = [self.datasource objectAtIndex:indexPath.row]; 
     cell.textLabel.text = [NSString stringWithFormat:@"%@", runnerCards.title]; 
    } 

    return cell; 
} 

편집 :

여기 대리자 메서드

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 

    // Return the number of sections. 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 

    // Return the number of rows in the section. 
    return self.datasource.count; 

} 

지금 몰래 데이터 소스 배열이 그 내용을 기록하는 것입니다 오전 문제가 있지만, numberOfRowsInSection는 0의 수를 반환합니다.

보기가 시작되고 처음으로 전환되는 방식은 다음과 같습니다. 이 코드는 초기 viewController의 코드입니다.

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ 
    NSString *title = [alertView buttonTitleAtIndex:buttonIndex]; 

    if ([title isEqualToString:@"side1"]){ 
     DeckBuilderTableViewController *deckBuilder = [[DeckBuilderTableViewController alloc]init]; 
     [deckBuilder fetchSide1Cards]; 
     [self performSegueWithIdentifier:@"deckBuilder" sender:self]; 
    } 

    if ([title isEqualToString:@"side2"]){ 
     DeckBuilderTableViewController *deckBuilder = [[DeckBuilderTableViewController alloc]init]; 
     [deckBuilder fetchSide2Cards]; 
     [self performSegueWithIdentifier:@"deckBuilder" sender:self]; 
    } 
} 
+0

속성 검사기에는 무엇이 있습니까? (상단 목록의 네 번째 아이콘) – sha

+0

이것은 귀속되지 않습니다. 첫 번째 입력란에 'Content : Dynamic Prototypes'가 표시됩니다. – sha

+0

스크린 샷을 다시 편집했는데 찾고있는 패널입니까? – TheM00s3

답변

0

cellForRowAtIndexPath 경우는 그것의 호출되지 못하고 있습니다 당신이 또는 섹션 및/또는 행 번호가 잘못된 것 같습니다 올바르게 설정되지 않은 delegate 때문. 확인 이러한 방법에서 올바른 값을 반환됩니다

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
//should return at least 1 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
//should return at least 1 
+0

위임 방법을 추가했습니다. 특정 시점에서 numberOfRowsINSections가 0 인 것을 볼 수는 있지만,''viewDidAppear 메소드''내에서''[self.tableView reloadData]''를 호출합니다. – TheM00s3

+0

주 스레드에서 reloadData를 호출하고 있습니까? – Arash

+0

그래,이 응용 프로그램은 멀티 스레딩을 사용하지 않습니다. – TheM00s3

0

귀하는 dataSource 위임 콘센트는 테이블 뷰 컨트롤러가 아닌 테이블보기로 설정해야합니다.

0

데이터 소스의 한 지점 수는 0이지만 다른 곳의 숫자는 0이므로 명확하게 지정해야합니다. 보기 확인 [Will | Did] 데이터를 두 번 가져 오지 않았는지 확인하고 잘못 수행하는 방법을 보여줍니다.

+0

viewDidAppear 및 viewDidAppear 메서드에는 코드가 없습니다. – TheM00s3

관련 문제