2014-09-04 3 views
0

그래서 this tutorial을 사용하여 UITableView에 잔액을 나타내는 사용자 지정 셀을 채 웁니다. 코드를 단계별로 실행할 때 올바른 양의 셀이 생성되고 (현재 테스트 데이터로 4 개만 표시됨) 해당 레이블의 텍스트가 그에 따라 설정됩니다.사용자 지정 셀이 만들어 지지만 표시되지 않습니다.

내 문제는 테이블이 화면에 표시되면 첫 번째 행/셀만 표시된다는 것입니다.

왜 이것이 발생했는지에 대한 통찰력은 대단히 감사하겠습니다!

이전 코드가 삭제되었습니다.

BalanceCell.h :

#import <UIKit/UIKit.h> 

@interface BalanceCell : UITableViewCell 
@property (weak, nonatomic) IBOutlet UILabel *nameLabel; 
@property (weak, nonatomic) IBOutlet UILabel *amountLabel; 
@property (weak, nonatomic) IBOutlet UILabel *modifiedLabel; 

@end 

편집 : @Sebyddd 제안으로

- (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 [_balances count]; 
} 

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

    if (cell == nil) { 
     cell = [[BalanceCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"]; 
    } 

    cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    cell.backgroundColor = [_hex colorWithHexString:_themeColourString]; 

    return cell; 
} 

-(void)tableView:(UITableView *)tableView willDisplayCell:(BalanceCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    Balance *item = [_balances objectAtIndex:indexPath.row]; 

    cell.nameLabel.textColor = _themeColour; 
    cell.nameLabel.text = item.name; 

    cell.amountLabel.textColor = _themeColour; 
    cell.amountLabel.text = [NSString stringWithFormat:@"%@%@", item.symbol, item.value]; 

    cell.modifiedLabel.textColor = _themeColour; 
    cell.modifiedLabel.text = [NSString stringWithFormat:@"%@", item.modified]; 

} 

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath  { 
    return 94; 
} 

, 내가 지금있는 viewDidLoad에 NIB 등록을 다음과 같이 내있는 TableView 위임 방법은 지금 방법.

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    [self.tableView registerNib:[UINib nibWithNibName:@"BalanceCell" bundle:nil] forCellReuseIdentifier:@"Cell"]; 
} 

이러한 변화는 내 코드가 더 정확하지만 still only the first cell is displayed 할 수 있습니다.

+0

사용자 셀의 셀 식별자를 "셀"로 설정 했습니까? – Sebyddd

+0

그래, 나는 Interface Builder에서 그렇게한다. –

답변

-1

이 튜 토리를 사용하십시오 : http://www.appcoda.com/uitableview-tutorial-storyboard-xcode5/, 귀하의 tuto가 조금 구식이며 따라하기가 어렵습니다!

+0

나는 그게 그의 문제를 도와 줄 것이라고 생각하지 않습니다. – Sebyddd

+0

그 자습서는 사용자 정의 셀을 사용하지 않습니다. 할당하고 시도하는 BalanceCell 인스턴스를 초기화 할 때 셀 또한 nil 있지만 UILabels nil 및 unsettable 원인이 발생했습니다. –

0

이 시도 :

if (cell == nil) { 
     [tableView registerNib:[UINib nibWithNibName:@"BalanceCell" bundle:nil] forCellReuseIdentifier:@"Cell"]; 
     cell = [[BalanceCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"]; 
} 
+0

제안에 감사드립니다! 매우 이상한 일로, 두 번째 행이 표시되고 다른 행은 표시되지 않습니다. [Screenshot] (http : // imgur.com/crhfJzR) –

+0

viewDidLoad 메서드에서 사용자 지정 셀을 등록하려고합니다. – Sebyddd

+0

여전히 첫 번째 셀입니다. –

1

세포가 만들어지고 난 높이 때에 프로퍼티를 설정하지 않을 생각 제대로 돌려지고합니다. 기본적으로 나는 모든 셀의 높이가 44임을 알고 있습니다. 셀이이 높이를 초과하면 표시되지 않을 수 있습니다.

당신은 당신의 세포 높이를 반환 대리자에서 (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 대표

를 사용하여 모든 셀의 높이를 조정의 tableview를 알 수 있습니다.

EDIT :

dequeueReusableCellWithIdentifier:를 사용하는 그러한 오브젝트 재사용 셀 큐에 존재하지 않는 경우 연관된 식별자 또는 전무로 있는 UITableViewCell 객체를 리턴한다.

대신 을 반환하는 dequeueReusableCellWithIdentifier:forIndexPath:을 사용하십시오. 연관된 재사용 식별자가있는 UITableViewCell 개체. 이 메소드는 항상 유효한 셀을 리턴합니다. 사용자 정의 셀의 nib/클래스를 등록해야합니다. viewDidLoad

+0

인터페이스 빌더의 셀 높이가 90이므로 해당 기간 동안 해당 델리게이트에서 94를 반환했습니다. –

+0

새 코드 목록과 스크린 샷으로 내 질문을 편집했습니다. 그래도 여전히 작동하지 않습니다. –

관련 문제