2012-06-17 3 views
0

어떤 이유로 키보드를 들으려면 내 섹션 헤더의 검색 필드를 선택할 수 없습니다. 또한, 내 테이블 뷰 셀에는 아무 것도 나타나지 않으며 그 이유를 모르겠습니다. 내 코드는 다음과 같습니다.내 uitextfield가 터치로 키보드를 열지 않는 이유는 무엇입니까?

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    self.view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; 

    self.tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain]; 
    self.tableView.delegate = self; 
    [self.view addSubview:self.tableView]; 
} 

- (BOOL)textFieldShouldReturn:(UITextField *)textField { 
    [self.searchField resignFirstResponder]; 

    return NO; 
} 

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

- (NSInteger)tableView:(UITableView *)tableView 
numberOfRowsInSection:(NSInteger)section { 
    return 8; 
} 

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

- (UIView *)tableView:(UITableView *)tableView 
viewForHeaderInSection:(NSInteger)section { 

    UIView *customHeader = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)]; 

    // Add search field 
    UITextField *field = [[UITextField alloc] initWithFrame:CGRectMake(40, 20, 250, 50)]; 
    field.borderStyle = UITextBorderStyleRoundedRect; 
    field.delegate = self; 
    [customHeader addSubview:field]; 

    return customHeader; 
} 

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 
    if (cell == nil) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier]; 

    NSLog(@"i am here"); 

    UITextField *field = [[UITextField alloc] initWithFrame:CGRectMake(40, 20, 250, 50)]; 
    field.borderStyle = UITextBorderStyleRoundedRect; 
    field.delegate = self; 
    [cell.contentView addSubview:field]; 
    } 

    return cell; 
} 
+1

테이블 뷰의 헤더 높이를 지정합니까? 가지고 있는지 확인하십시오 - tableView : heightForHeaderInSection : 그리고 검색 막대가있는 부분에 대한 반환 값은 50 – Ladislav

+0

입니다. – Vadoff

+0

문제 없으며 아래 답변을 수락하십시오 :) – Ladislav

답변

1

해당 섹션에 헤더 높이를 지정하지 않았기 때문에 작동하지 않는다고 말할 수 있습니다.

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { 
    return 50.0; 
} 

두 개 이상의 섹션이있는 경우 원하는 섹션에만이 작업을 수행해야합니다.

0

왜 nib 파일이나 스토리 보드를 사용하지 않습니까? 사과 문서에 따르면, 당신은 당신이 뷰 계층을 설정하는

-loadView 

메소드를 오버라이드 (override) 스토리 보드 또는 코코아 콩 파일에서의 UIViewController의보기를로드 할 수없는 경우. Read view management section 아마도 검색 필드 문제를 해결할 것입니다. 는 두 번째 문제는 cellidentifier

NSString *cellIdentifier = @"Your identifier"; 

나는 그것이 전무가 될 수 있다고 생각하지 않습니다를 설정 해결합니다. 내 대답이 도움이되기를 바랍니다. 그렇지 않은 경우 댓글을 남기십시오.

관련 문제