2015-01-23 2 views
0

왜 내 셀의 제목과 부제목을 표시 할 수 없는지 알 수 없습니다. NSLog() 통해 문자열 개체를 가져 오는 시도했다 그러나 array_Stacks 배열 (Stack 개체) 테스트 개체의 메모리 위치를 성공적으로 인쇄하는 NSLog()에서 제쳐두고 출력을받지 못합니다.제목 및 NSLog가 cellForRowAtIndexPath에서 실행되지 않음

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SimpleCell" forIndexPath:indexPath]; 

    if (!cell) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"SimpleCell"]; 
    } 

    NSString *cell_Title = [[array_Stacks objectAtIndex:[indexPath row]] title]; 
    NSString *cell_Subtitle = [[array_Stacks objectAtIndex:[indexPath row]] subject]; 

    NSLog(@"%@", cell_Title); 

    NSLog(@"%@", [array_Stacks objectAtIndex:[indexPath row]]); 
    NSLog(@"%@", cell_Subtitle); 

    cell.textLabel.text = cell_Title; 
    cell.textLabel.tintColor = [cp color_master_tan]; 
    cell.detailTextLabel.text = cell_Subtitle; 
    cell.detailTextLabel.tintColor = [cp color_master_tan]; 
    //cell.imageView.image = [UIImage imageNamed:@"asset_Cell"]; 

    return cell; 
} 

참고 :

여기 내 cellForRowAtIndexPath: 방법이다 "CP는"내 컬러 팔레트 객체이며 UIColor 객체를 반환합니다. 여기

당신은 당신의 Stack initWithTitle:...@""에 문자열을 설정하는 Stack.m

#import "Stack.h" 
#import "FlashCard.h" 

/* 
Notes 

* Need to get the name of the creator and add it to the default init. 

*/ 

@implementation Stack 
{ 
    NSMutableArray *array_flashCard; 
} 
@synthesize title, subject, creator, array_FlashCard; 

#pragma mark - Initializers 

- (id)init { 
    return [self initWithTitle:@"New Stack" subject:@"No Subject" creator:@"None Listed" array:array_FlashCard]; 
} 

- (id)initWithTitle:(NSString *) ttl subject:(NSString *) sbj creator:(NSString *) ctr array:(NSMutableArray *) arr { 
    self = [super init]; 
    if (self) { 
     title = ttl; 
     subject = sbj; 
     creator = ctr; 
     array_FlashCard = arr; 

     title = [[NSString alloc] init]; 
     subject = [[NSString alloc] init]; 
     creator = [[NSString alloc] init]; 
     array_FlashCard = [[NSMutableArray alloc] init]; 

    } 
    return self; 
} 

#pragma mark - Array Operations 

- (void)addFlashCardToArray:(FlashCard *) flashcard { [array_FlashCard addObject:flashcard]; } 

@end 
+0

문자열이 비어 있습니다. –

+0

먼저, 전혀 호출되지 않습니까? 중단 점을 설정하고 트리거가 발생하는지 확인하십시오. 그렇지 않다면 테이블 뷰의 데이터 소스로 무엇을 설정 했습니까? 얼마나 많은 행이 테이블에 있는지 말하는 메소드가 호출됩니까? 그렇다면 무엇이 반환됩니까? –

+0

두 번째 NSLog는 어레이의 Stack 객체에 대한 메모리 주소 인 올바른 정보를 출력하므로 객체가 존재하고 메소드가 트리거되고 있음을 알 수 있습니다. 파일 소유자가 설정되었습니다. 문제는 문자열이 비어 있더라도 적어도 터미널에서 타임 스탬프를 사용하여 'nil'을 얻는 것이지만 아무 것도 얻지 못합니다. – Cole

답변

1

입니다.

title = ttl; 
    subject = sbj; 
    creator = ctr; 
    array_FlashCard = arr; 

    title = [[NSString alloc] init]; // Throw away previous value; assign new empty string. 
    subject = [[NSString alloc] init]; // Throw away previous value; assign new empty string. 
    creator = [[NSString alloc] init]; // Throw away previous value; assign new empty string. 
    array_FlashCard = [[NSMutableArray alloc] init]; // Throw away previous value; assign new empty array. 
+0

이렇게했습니다. 아직도 다른 NSLogs에 대한 nil이없는 타임 스탬프가 표시되지 않는 이유는 확실하지 않지만 지금은 내 제목이 표시됩니다. 감사! – Cole

+1

다시 @Cole, 문자열은 유효하지 않은 객체 _이며 nil이 아닙니다. 빈 문자열은'nil '과 같지 않습니다. –

-1

대부분의 경우에 작은 실수라는 것을 이해해야합니다. 따라서 다음 사항을 확인해야합니다.

  1. 위임자와 데이터 원본이 올바르게 설정되었는지 여부. 그리고 위임 메서드가 제대로 호출되는지 여부를 구분 점으로 설정하십시오.
  2. 데이터 원본이 0 개체를 반환하지 않는지 여부입니다. 데이터 소스에 오브젝트가없는 경우 cellForRowAtIndexPath이 호출되지 않기 때.입니다.

호프가 도움이되기를 바랍니다. 아마 뭔가를 놓칠 수도 있습니다.

이상한 것은 이미 title, subject, creatorarray_FlashCard을 할당하고 있습니다. 하지만 다시 초기화하면 더 이상 비어있게됩니다.

관련 문제