그래서 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 할 수 있습니다.
사용자 셀의 셀 식별자를 "셀"로 설정 했습니까? – Sebyddd
그래, 나는 Interface Builder에서 그렇게한다. –