2011-04-28 5 views
0

저는 iPhone 프로그래밍에 익숙하지 않고 기본적인 문제에 대한 답변을 찾기가 어렵습니다. UIView에서 단일 행 UITableview를 만들고 셀 클릭을 다른 UITableView 화면으로 리디렉션하여 사용 가능한 값 중 하나를 선택하려고합니다. 모든보기가 선택보기에서 선택 될 때까지 잘되지만, 뒤로 단추를 클릭하면 새 선택한 값이 반영되지 않습니다. 나는 나의 소명보기UIDataView 선택이 게시되지 않았습니다.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    // open a alert with an OK and cancel button 
    UIViewController *nextViewController = nil; 
    nextViewController = [[CategorySelectionView alloc] initWithStyle:UITableViewStyleGrouped]; 
    ((CategorySelectionView *)nextViewController).category = parentCategory; 
    [self.navigationController pushViewController:nextViewController animated:YES]; 
    [nextViewController release];//break; 

} 

On selection View 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

    // If there was a previous selection, unset the accessory view for its cell. 
    NSManagedObject *currentCategory = category; 

    if (currentCategory != nil) { 
     NSInteger index = [categoryTypes indexOfObject:currentCategory]; 
     NSIndexPath *selectionIndexPath = [NSIndexPath indexPathForRow:index inSection:0]; 
     UITableViewCell *checkedCell = [tableView cellForRowAtIndexPath:selectionIndexPath]; 
     checkedCell.accessoryType = UITableViewCellAccessoryNone; 
    } 

    // Set the checkmark accessory for the selected row. 
    [[tableView cellForRowAtIndexPath:indexPath] setAccessoryType:UITableViewCellAccessoryCheckmark];  

    category = [categoryTypes objectAtIndex:indexPath.row]; 

} 

이 추출 형태의 애플 개발자 레시피 코드입니다하지만 나를 위해 작동하지 않는 경우에이 코드

을 사용하고 있습니다. 어떤 도움이라도 정말로 감사 할 것입니다. 또한 내가 선택기로 tableView 화면을 사용하는 예제로 리디렉션 될 수 있다면 똑같이 도움이 될 것입니다. 당신이 아래의 세포 사용을 해제하려면 여러분의 도움이

+0

아래로 사용? – Jhaliya

+0

@ Jhaliya : 명확하지 않은 경우 미안합니다. View1의 UICell에서 View2를 호출하여 사용자가 값을 선택합니다. 그래서 view2에서 값을 선택하고 뒤로 버튼을 클릭하면 view1에서 선택된 값이 업데이트되지 않습니다. –

+0

view1에 새 값을 추가하고 있습니까? UICell의 view1 하위보기입니까? – Jhaliya

답변

0

를 기대하여 didSelectRowAtIndexPath

[tableView deselectRowAtIndexPath:indexPath animated:NO];  

그래서 코드는 아래와 같이해야합니다.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

    // If there was a previous selection, unset the accessory view for its cell. 
    NSManagedObject *currentCategory = category; 

    if (currentCategory != nil) { 
     NSInteger index = [categoryTypes indexOfObject:currentCategory]; 
     NSIndexPath *selectionIndexPath = [NSIndexPath indexPathForRow:index inSection:0]; 
     UITableViewCell *checkedCell = [tableView cellForRowAtIndexPath:selectionIndexPath]; 
     checkedCell.accessoryType = UITableViewCellAccessoryNone; 
    } 

    // Set the checkmark accessory for the selected row. 
    [[tableView cellForRowAtIndexPath:indexPath] setAccessoryType:UITableViewCellAccessoryCheckmark];  
    category = [categoryTypes objectAtIndex:indexPath.row]; 

    //Add it to deselect the selected cell 
    [tableView deselectRowAtIndexPath:indexPath animated:NO];  
} 

편집 :

당신이, 뒷면 버튼을 클릭하는에 대한 이벤트를 얻을 다음 UITableView 인스턴스에서 reloadData 메소드를 호출 (당신의 tableview에 의해 표시되는) 데이터를 업데이트. 업데이트 된 값을 얻으려면 UITableView의 reloadData 메서드를 사용할 수 있습니다.

하지 반영 당신이 상태를 의미

[tableView reloadData]; 
+0

감사합니다. Jhaliya, 네, 거기에 있었고 디버깅에 댓글을 달았습니다. 다시 가져 오면 도움이되지 않습니다. ( –

+0

@ Gaurav Arora : 업데이트 된 답변보기 ... – Jhaliya

관련 문제