2014-02-08 4 views
1

사용자 정의 셀이있는 UITableView가 있습니다. 셀 안에는 자리 표시 자 텍스트가있는 UITextField가 있습니다. 내가 cellForRowAtIndexPath에서 자리 표시자를 설정하고 싶습니다만, 설정하려고 할 때 자리 표시자는 (null)이라고 말합니다. 또한, 그 자리 표시 자로 서식을 싶습니다 "기간 (셀 번호를 tableView)"그래서 tableView 맨 가장 가까운 셀에 대한 "기간 1"말할 것이라고, 위쪽에서 두 번째 말할 것이라고 "기간 2". 번호 매기기를하는 방법이나 셀이 null을 인쇄하는 이유를 알아낼 수 없습니다. 사용자 지정 셀에cellForRowAtIndexPath의 셀에 UITextField 자리 표시 자 설정

- -

NSString *rowString = [NSString stringWithFormat:@"Period %@", self.rowNumber]; 
self.classText = [[UITextField alloc] init]; 
self.classText.delegate = self; 
self.classText.placeholder = rowString; 
self.classText.frame = CGRectMake(14, 3, 320, 40); 
self.classText.keyboardAppearance = UIKeyboardAppearanceDark; 
self.classText.font = [UIFont fontWithName:@"HelveticaNeue" size:17]; 
//[self.classText addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged]; 
[self addSubview:self.classText]; 

cellForRowAtIndex 경로에서 -

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

    SchoolCell *cell = nil; 
    static NSString *AutoCompleteRowIdentifier = @"AutoCompleteRowIdentifier"; 
    cell = [tableView dequeueReusableCellWithIdentifier:AutoCompleteRowIdentifier]; 
    if (cell == nil) { 
     cell = [[SchoolCell alloc] 
       initWithStyle:UITableViewCellStyleDefault reuseIdentifier:AutoCompleteRowIdentifier]; 
    } 
    cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    cell.rowNumber = @"test"; 

    return cell; 
} 
+0

어떤 기능으로 텍스트 필드를 만드나요? 코드가 나열되어 있지만 참조 할 때 참조가 없습니다. – Putz1103

+0

셀 @ Putz1103에서 – matthew

답변

0

사용자 정의 셀에 당신이 classText를 초기화 코드 줄을 배치하는 다음 코드는? classText를 초기화 한 후에 cellForRowAtIndex 메소드에서 rowNumber를 설정하고있을 가능성이 높습니다. rowNumber를 매개 변수로 사용하는 사용자 정의 init 메소드를 작성하거나 rowNumber를 설정 한 후에 cellForRowAtIndex에서 나중에 호출 할 수있는 rowString에 메소드를 작성한 다음 classText 초기화 코드를 그 안에 넣으십시오.