2013-10-14 7 views
0

선택 목록을 표시하는 사용자 지정 키보드를 만들려고합니다.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 

답변

0

님의 -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

이처럼 수행 구현 잊어 버린 : 여기

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 1; 
} 
+0

numberOfSectionsInTableView : 선택 사항입니다. 내가 어쨌든 그것을 구현하고 결과가 동일하다는 것을 확신하기 위해서. – Leontien

0

문제는 initWithFrame을있는 tableView가 스토리 보드에서 생성되고, 따라서 initWithCoder가 호출되지 것입니다.

해결하려면 initWithFrame 대신 initWithCoder를 재정의하고 initWithFrame을 호출하는 init 메서드를 재정의하지 마십시오.

관련 문제