2012-03-15 4 views
0

UINavigationControllerUITableViewController을 루트 컨트롤러로 사용하고 있습니다. UINavigationControllerUIPopoverController 안에 있습니다. UITableViewController은 도청시 UITableView을로드하는 UITableViewCell (UISwitch) 및 UITableViewCell (UITableViewCellAccessoryDisclosureIndicator)을 포함합니다.UITableViewCell의 UISwitch

내 문제는 UISwitch으로 스 와이프 한 다음 다른 셀을 탭하면 didSelectRowAtIndexPath이 호출되지 않는다는 것입니다. 다시 탭하면 다시 호출됩니다. 스 와이프하는 대신 UISwitch 번을 터치해도 아무런 문제가 없습니다.

문제는 iOS4에서만 발생합니다. iOS5에서 잘 작동합니다!

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
static NSString *CellIdentifier1 = @"Cell1"; 
static NSString *CellIdentifier2 = @"Cell2"; 

// Configure the cell... 
NSUInteger row = [indexPath row]; 
UITableViewCell *cell = nil; 
switch (row) { 
    case 0: { 
     cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1]; 
     if (cell == nil) { 
      cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease]; 
     } 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 
     cell.textLabel.text = [controllers objectAtIndex:row]; 
     cell.accessoryType = UITableViewCellAccessoryNone; 
     UITextField *passwordTextField = [[UITextField alloc] initWithFrame:CGRectMake(160, 11, 400, 30)]; 
     passwordTextField.adjustsFontSizeToFitWidth = YES; 
     passwordTextField.placeholder = @"Richiesta"; 
     passwordTextField.keyboardType = UIKeyboardTypeDefault; 
     passwordTextField.secureTextEntry = YES; 
     passwordTextField.tag = 100; 
     [passwordTextField addTarget:self action:@selector(passwordChanged:) forControlEvents:UIControlEventEditingChanged]; 
     passwordTextField.text = password; 
     [cell addSubview:passwordTextField]; 
     [passwordTextField release]; 
     break; 
    } 

    case 1: { 
     cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1]; 
     if (cell == nil) { 
      cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease]; 
     } 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 
     cell.textLabel.text = [controllers objectAtIndex:row]; 
     cell.accessoryType = UITableViewCellAccessoryNone; 
     UITextField *pinTextField = [[UITextField alloc] initWithFrame:CGRectMake(160, 11, 400, 30)]; 
     pinTextField.adjustsFontSizeToFitWidth = YES; 
     pinTextField.placeholder = @"Richiesta"; 
     pinTextField.keyboardType = UIKeyboardTypeDefault; 
     pinTextField.secureTextEntry = YES; 
     pinTextField.tag = 101; 
     [pinTextField addTarget:self action:@selector(pinChanged:) forControlEvents:UIControlEventEditingChanged]; 
     pinTextField.text = aspin; 
     [cell addSubview:pinTextField]; 
     [pinTextField release]; 
     break; 
    } 
    case 2: { 
     cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier2]; 
     if (cell == nil) { 
      cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier2] autorelease]; 
      cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
     } 
     UITableViewController *controller = [controllers objectAtIndex:row]; 
     cell.textLabel.text = controller.title; 
     cell.detailTextLabel.text = @"Busta Crittografica P7M (CAdES)"; 
     envelopeType = cell.detailTextLabel.text; 
     break; 
    } 
    case 3: { 
     cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1]; 
     if (cell == nil) { 
      cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease]; 
     } 
     cell.textLabel.text = @"Dichiaro di aver preso visione del documento, di sottoscriverne il contenuto e di essere consapevole della validità legale della firma apposta"; 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 
     cell.textLabel.numberOfLines = 5; 
     cell.textLabel.lineBreakMode = UILineBreakModeWordWrap; 
     //add a switch 
     UISwitch *switchview = [[UISwitch alloc] initWithFrame:CGRectZero]; 
     [switchview addTarget:self action:@selector(declarationChanged:) forControlEvents:UIControlEventValueChanged]; 
     switchview.on = declaration; 
     cell.accessoryView = switchview; 
     [switchview release]; 
     break; 
    } 
} 
return cell; 

}

그리고 내 didSelectRowAtIndexPath 방법은 다음과 같습니다 :

내 cellForRowAtIndexPath 방법은

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
NSUInteger row = [indexPath row]; 
switch (row) { 
    case 0: { 
     [[[tableView cellForRowAtIndexPath:indexPath] viewWithTag:100] becomeFirstResponder]; 
     break; 
    } 
    case 1: { 
     [[[tableView cellForRowAtIndexPath:indexPath] viewWithTag:101] becomeFirstResponder]; 
     break; 
    } 
    case 2: { 
    ((CheckListController *)[self.controllers objectAtIndex:2]).contentSizeForViewInPopover = self.view.bounds.size; 
     self.contentSizeForViewInPopover = self.view.bounds.size; 

     [self.navigationController pushViewController:[self.controllers objectAtIndex:2] 
              animated:YES]; 
     break; 
    } 
    default: 
     break; 
} 
[tableView deselectRowAtIndexPath:indexPath animated:YES]; 

}

그것은 매우 어려운 문제이고 그래서 당신의 도움이 필요 !

감사합니다.

+0

* cellForRowAtIndexPath : * 및 * didSelectRowAtIndexPath에 대한 코드를 제공 할 수 있습니까? *? 두 개의 셀을 만드는 데 두 개의 다른 식별자를 사용하고 있습니까? (* CellIdentifier1 * 참조)? –

+0

내 질문을 편집했습니다. – Giorgio

+0

스 와이프하여 * UISwicth *를 탭하는 것이 무엇을 의미합니까? 내게는 선택 가능한 셀을 선택하는 데 아무런 차이가 없다. –

답변

0

올바른 해결책이 될 수 있는지는 잘 모르겠지만 선택자 인 declarationChanged: 선택기 내에서 표 셀을 선택 취소 할 수 있습니다.

- (void)declarationChanged:(id)sender 
{ 
    // do your stuff here... 
    //[tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:animated]; 

    UISwitch* s = (UISwicth*)sender; 
    [s resignFirstResponder]; 
} 

희망이 있습니다.

+0

도움 주셔서 감사합니다. 나는 당신에게 제안을했지만 행운이 없었습니다. 문제를 재현 한 예제를 만들어보고 게시 해 드리겠습니다. – Giorgio

+0

제발 조르지오, 제 편집 참조하십시오. –

+0

어제도 resignFirstResponder를 사용해 보았지만 사용하지는 않았습니다. 어쨌든 나는 내 문제를 해결했다. 내 질문에 내 마지막 코멘트를 참조하십시오. 고맙습니다. – Giorgio