2013-02-24 2 views
0

레이블과 TextField가 포함 된 TabelViewCell로 펜촉을 만든 다음이 셀을 TableView에 두 행만로드합니다. 항목의 이름과 가격을 캡처하고 싶습니다. 따라서 indexPath.row 값에 액세스 할 수 있으므로 cellForRowAtIndexPath 메서드에서 각 레이블을 업데이트했습니다. 셀의 TextField에서 데이터 가져 오기

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *simpleCellIdentifier = @"AddBudgetItemCell"; 

    SCAddBudgetItemCell *cell = (SCAddBudgetItemCell *)[tableView dequeueReusableCellWithIdentifier:simpleCellIdentifier]; 

    if(cell == nil) 
    { 
     NSArray *nib = [[NSBundle mainBundle] loadNibNamed:simpleCellIdentifier owner:self options:nil]; 

     cell = [nib objectAtIndex:0]; 
    } 

    cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    cell.dataTextField.delegate = self; 

    switch (indexPath.row) 
    { 
     case 0: 
      cell.titleLabel.text = @"Item"; 
      break; 

     case 1: 
      cell.titleLabel.text = @"Price ¥"; 
      break; 

     default: 
      break; 
    } 

    return cell; 
} 

그러나 나는 내가 만든 변수 "셀"나 IndexPath.row 값 중 하나에 액세스 할 수 없기 때문에 나는 텍스트 필드의에서 데이터를 검색 할 수있는 방법을 모르겠어요.

답변

0

두 가지 옵션이 있습니다. 만약 내부에 SCAddBudgetItemCell 그런 다음 텍스트 필드의 문자열이 포함 된 아마 당신이 yourtexfield이 SCAddBudgetItemCell 내부의 UITextView입니다 cell.yourtextfield.text (같은 것을 수행하여의 ViewController에서 액세스 할 수있는 속성이 있습니다.

다른 옵션은 뷰를 확인하는 것입니다 컨트롤러는 UITextFieldDelegate에 응답하고 델리게이트 메서드를 구현하여 사용자가 편집 할 때 문자열을 저장합니다.

- (void)textFieldDidBeginEditing:(UITextField *)textField{ 
    //Whenever people start editing your textfield 
} 
-(BOOL)textFieldShouldReturn:(UITextField *)textField{ 
    // 
return YES; 
} 
-(void)textFieldDidEndEditing:(UITextField *)textField 
{ 
    //This is obvious. Whenever they end 
}