2010-03-29 10 views
0

나는 세 개의 셀을 가지고 있으며 그 안에는 각 텍스트 필드가 있습니다. 이제 사용자가 텍스트 상자를 클릭하면됩니다. 이 메소드 textFieldDidEndEditing은 사용자가 입력하는 값을 제공하지만 텍스트 필드의 태그를 가져 오지 않습니다. 여기 TextField의 태그

내 코드입니다 :

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section 
{ switch (section) 
    { case 0: return @""; 
     case 1: return @""; 
     default:return @""; 
    } 
} 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
     if(optconscodecount != 0 && gotOK == 2) 
     return 2; 
    else 
     return 1; 
} 
// Customize the number of rows in the table view. 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    switch(section) 
    { case 0: try=1; return conscodecount; 
     case 1: try=2; return optconscodecount; 
     default:return 0;} 
} 
// Heights per row 
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ int section = [indexPath section]; 
    //int row = [indexPath row]; 
    switch (section) 
    {case 0:return 80.0f; 
    case 1:return 80.0f; 
    default:return 80.0f;} 
} 
// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSLog(@"\n%@", appDelegate.conscodeNameArray); 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
    } 
     // Set up the cell... 
    row = [indexPath row]; 
    section = [indexPath section]; 
    switch (section) 
    {case 0:try=1;cell = [tableView dequeueReusableCellWithIdentifier:@"textCell"]; 
      if (!cell) 
      {cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"textCell"] autorelease]; 
      UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20.0f, 10.0f, 280.0f, 20.0f)]; 
       [label setText:[appDelegate.conscodeNameArray objectAtIndex:row]];[cell addSubview:label]; [label release]; 
       [cell addSubview:[[UITextField alloc] initWithFrame:CGRectMake(20.0f, 40.0f, 280.0f, 30.0f)]]; 
      } 
      UITextField *tf = [[cell subviews] lastObject]; 
      tf.placeholder = [appDelegate.conscodeNameArray objectAtIndex:row]; 
      tf.tag =tagcount; 
      tagcount=tagcount+1; 
      tf.delegate = self; 
      tf.borderStyle = UITextBorderStyleRoundedRect; 
      return cell; 
      break; 

     case 1: 
      try=2; 
      cell = [tableView dequeueReusableCellWithIdentifier:@"textCell"]; 
      if (!cell) 
      { 
       cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"textCell"] autorelease]; 

       UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20.0f, 10.0f, 280.0f, 20.0f)]; 
       [label setText:[appDelegate.optconscodeNameArray objectAtIndex:row]]; 
       [cell addSubview:label]; 
       [label release]; 
       [cell addSubview:[[UITextField alloc] initWithFrame:CGRectMake(20.0f, 40.0f, 280.0f, 30.0f)]]; 
      } 
      UITextField *my = [[cell subviews] lastObject]; 
      my.tag = 0; 
      my.tag = my.tag+1; 
      my.placeholder = [appDelegate.optconscodeNameArray objectAtIndex:row]; 
      my.delegate = self; 
      my.borderStyle = UITextBorderStyleRoundedRect; 
      return cell; 
      break; 
      return cell;  
      break; 
     default: 
      break; 
    } 
return cell; 
} 
+0

질문을 업데이트하여 지금까지 작성한 HTML을 포함하십시오. 그것을 더 잘 설명하도록 노력하십시오. – thecoshman

+0

왜 텍스트 필드에서 중계하고 있습니까? 당신은 텍스트 필드를 셀 안에 넣을 것입니까? 즉, UITableViewCell을 사용자 지정하는 것입니다. 텍스트 필드를 셀에 정확히 추가하는 방법을 알려주십시오. – Manjunath

답변

0

nameField.tag = 1; 당신이 인스턴스 변수에 각각의 텍스트 필드를 유지한다면

agefield.tag = 2; 

// 대리자 방법에 당신이 있던 현장 확인하려면 대리자 메서드의 단순 비교를 할 수있는,

if (textField.tag == 1) { 
NSLog(@" clicked in Name field"); 

} else if (textField.tag ==2) { 
NSLog(@" clicked in Age field"); 
} 
+0

안녕하세요 .. 우리는 런타임에 no.of 필드는 배열의 객체 번호에 따라 달라질 수 있습니다. 위의 지정된 메소드에서 태그를 가져 오는 것을 도와주세요. 태그를 얻지 못하고 있습니다. 첫 번째 텍스트인지 여부를 지정합니다. 필드 또는 네 번째 텍스트 필드 – mukeshpawar

+0

안녕하세요, 자세히 설명해 주시겠습니까? – SST

+0

나는 동적으로 텍스트 필드를 만들고있다. 테이블에 두 개의 섹션이있다. 섹션 1에서 모든 텍스트 필드 값이 하나의 배열에 추가되고 텍스트 필드 값이 다른 배열에 있어야하므로 태그를 원한다. 조건을 부여 할 수있다. 난 대리인이 방법에 – mukeshpawar

0

을 확인 편집을 마쳤습니다. 연관 배열을 사용하여 인스턴스에서 필드 이름으로 또는 그 반대로 완전히 동적으로 만들더라도이 작업을 수행 할 수 있습니다.

+0

안녕하세요 ... 나는 u를 얻을 수 없었습니다 .. can u는 몇 가지 예제 코드를 통해 자세히 설명합니다 .. – mukeshpawar

관련 문제