선택 목록을 표시하는 사용자 지정 키보드를 만들려고합니다.xib에서 UITableView에 데이터 없음
UITableView
만 포함 된 xib 파일 (UIView
기준)을 만들었습니다.
.h 및 ListKeyBoardView.m
(아래 코드 참조)을 만들었습니다. ListKeyBoardView.m
에서 nib-file을로드하고 xib에서 UITableView
을 Interface Builder를 통해 UITableView에 연결합니다. nib 파일을로드 한 후 UITableView
의 프레임 크기를 확인했습니다. 인터페이스 빌더의 UITableView
과 크기가 같으므로 올바르게 연결되어있는 것 같습니다. 그러나 내가 응용 프로그램을 실행하고보기가 표시되면, 그것은 완전히 비어 있습니다.
코드에서 UITableView
에 대한 대리자 및 데이터 소스를 설정했으며 tableView:numberOfRowsInSection:
메서드가 호출되었지만 (반환 값은 6), tableView:cellForRowAtIndexPath:
은 호출되지 않았습니다.
다른 오류를 확인하려면 코드에서 수동으로 UITableView
을 만든 다음 (문제가 발생한 행 참조) 잘 작동합니다. 내가 누락 된 것?
#import "ListKeyBoardView.h"
@interface ListKeyBoardView() <UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *listTableView;
@property (strong, nonatomic) NSMutableArray *listData;
@end
@implementation ListKeyBoardView
- (id)init {
return [self initWithFrame:CGRectMake(0, 0, 320, 250)];
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[[NSBundle mainBundle] loadNibNamed:@"ListKeyboard" owner:self options:nil];
// self.listTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 200)];
NSLog(@"Frame = %f, %f", self.listTableView.frame.size.width, self.listTableView.frame.size.height);
[self addSubview:self.listTableView];
self.listTableView.delegate = self;
self.listTableView.dataSource = self;
[self.listTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"ListItem"];
self.listData = [[NSMutableArray alloc] init];
[self.listData addObject:@"een"];
[self.listData addObject:@"twee"];
[self.listData addObject:@"drie"];
[self.listData addObject:@"vier"];
[self.listData addObject:@"vijf"];
[self.listData addObject:@"zes"];
}
return self;
}
#pragma mark UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.listData count];
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"ListItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
// Configure the cell...
cell.textLabel.text = [self.listData objectAtIndex:indexPath.row];
return cell;
}
@end
numberOfSectionsInTableView : 선택 사항입니다. 내가 어쨌든 그것을 구현하고 결과가 동일하다는 것을 확신하기 위해서. – Leontien