2012-03-03 4 views
0

저는 IOS 개발을 처음 접했기 때문에 무식한 질문 일 경우 사과드립니다.ARC를 켠 후 UITableViewCell.contentView 오류가 발생했습니다.

'

UILabel *label = (UILabel *)[cell.contentView viewWithTag:labelTag]; 

콘솔 출력은 다음과 같습니다

ARC를 사용하려면 코드를 리팩토링 후, 나는 다음과 같은 라인이 실행될 때 발생하는 SIGABRT 오류를 받기 시작했습니다 NSInvalidArgumentException '이유'- [__ NSArrayM가있는 contentView] : 미정 선택기 인스턴스 0x1acba0 '

해당 광고의 컨텍스트로 전송된다 :

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    const NSInteger labelTag = 1; 
    const NSInteger textFieldTag = 2; 

    UITableViewCell *cell = nil; 

    if([indexPath section] == 0) { 
     if([indexPath row] == 0) { 
      //this is the username row. Set the label accordingly. 

      cell = [[TextFieldCellController alloc] init]; 

      UILabel *label = (UILabel *)[cell.contentView viewWithTag:labelTag]; 
      label.text = @"Username"; 
     } 
     else if([indexPath row] == 1) { 
      //this is the row that contains the password input. Set the label and 
      //change the textfield to use a password input style. 

      cell = [[TextFieldCellController alloc] init]; 

      UILabel *label = (UILabel *)[cell.contentView viewWithTag:labelTag]; 
      label.text = @"Password"; 

      UITextField *text = (UITextField *)[cell.contentView viewWithTag:textFieldTag]; 
      text.secureTextEntry = YES; 


     } 
    } 
    return cell; 
} 

콘솔 창에서 놀고 있었는데 그 줄에 중단 점을 넣은 후 "print cell.contentView"를 입력하면 "contentView라는 구성원이 없습니다."라는 메시지가 나타납니다. 그게 도움이 될지 모르겠습니다.

미리 도움을 청하십시오.

편집 :

죄송합니다, TextFieldCellController 레이블과 텍스트 필드를 포함하는 펜촉을로드있는 UITableViewCell의 하위 클래스입니다.

@implementation TextFieldCellController 

@synthesize label; 
@synthesize textField; 

- (id)init { 
    self = (TextFieldCellController *)[[NSBundle mainBundle] loadNibNamed:@"TextFieldCell" owner:self options:nil]; 
    return self; 
} 
+0

메시지는'cell'이'NSArray' 인터페이스의 private 구현 인'__NSArrayM' 클래스의 객체를 가리키고 있음을 알려줍니다. 그래서 우리에게'- [TextFieldCellController init]'메소드를 보여 주라. –

+0

TextFieldCellController 이것은 무엇입니까?, 그리고 당신은 제대로 세포를 생성하지 않습니다.이 링크를 참조하십시오 http://stackoverflow.com/questions/9494281/how-is-the-code-for-uploading-the-parsed-data- to-the-tableview/9494402 # 9494402. – Kamarshad

+0

서브 클래스를 설명하기 위해 초기 질문을 업데이트했습니다. – Leedrick

답변

0

이는 구현 방법이 cellForRowAtIndexPath입니다. 왜 dequeueReusableCellWithIdentifier:에 전화하지 않으십니까?

alloc init을 호출하여 테이블보기 셀을 만들 수 없습니다. 지정된 이니셜 라이저는 initWithStyle:reuseIdentifier:입니다. 나는 당신을 믿는다 해야한다.

마지막으로, 나는이 TextFieldCellController에 대해 매우 의심 스럽습니다. 그것이 UITableViewCell 서브 클래스라면, 다음과 같이 초기화하면 태그에 1 또는 2의 하위 뷰가 없게됩니다. UITableViewCell 서브 클래스가 아닌 경우 서브 클래스는 무엇입니까? 펜촉에서 셀을로드하기 위해 UIViewController를 사용하지 않기를 바랍니다. 그것은 대단히 틀릴 것입니다.

+0

dequeueReusableCellWithIdentifier가 선택 사항이라고 생각 했습니까? 내가 재사용 할 수있는 커스텀 셀을 갖는 방법을 찾아 내려고 노력했다. ARC를 사용할 때까지이 작업이 진행되었습니다. 더 나은 방법을 말해 줄 수 있어요? 초기 질문을 업데이트했습니다. – Leedrick

관련 문제