2009-11-13 5 views
1

모델 값을 설정하기 위해 다양한 UIControl을 사용하는 일련의 UITableViewCell 요소가 있습니다.모델이 변경 될 때 UI 업데이트

모델을 변경하면 모델의 계산 된 속성을 표시하는 UITableViewCell을 업데이트하는 방법을 찾는 데 어려움이 있습니다.

AppDelegate에 모델을 배치하고 RootViewController에서 모델에 직접 액세스했습니다. 각 UITableViewCell 구현에는 변경이 이루어질 때 모델을 업데이트하는 메서드가 있습니다.

하지만 업데이트를 표시하기 위해 디스플레이를 새로 고치는 방법을 모르겠습니다. (두 요소에 동일한 요소를 연결하려고했지만 동작이 완료되는 순서가 일관되지 않아 먼저 디스플레이를 다시로드 한 다음 모델을 업데이트합니다.

도움을 주시면 감사하겠습니다.

감사합니다 ..

답변

1

동일한 요소를 개의 액션에 연결해 보았습니다. 그러나, 조치가 완료되는 순서는 먼저 디스플레이를 다시로드, 그래서 다음 모델을 업데이트, 일치하지

모델, 단 하나의 액션을 사용하여 첫 번째 업데이트를 시도하고 그이 완료되면 디스플레이를 업데이트합니다. 당신의 문제가이 두 가지를 동기화하고있는 것처럼 보입니다. 따라서 모델 업데이트 기능 후에 display-updating 함수를 호출하는 것이 좋습니다.

+0

Thanks Luvieere, UITableViewCell에는 setModel 함수가 있으며 RootViewController에서 update 함수를 호출해야합니다. UITableViewCellController 개체에서 RootViewController 변수를 만들고 해당 updateDisplay 메서드를 호출합니까? 올바른 방법입니까? – Prasanna

+0

그 중 하나 또는 귀하의 RootViewController 함수를 정적으로 업데이트해야하므로 [RootViewController update]와 같이 호출 할 수 있습니다. – luvieere

+0

@Prasanna, 각 UITableViewCell (TVC)에 대해 하나의'UITableViewCellController' (TVCC)를 어떻게 만듭니 까? – ma11hew28

0

당신이 NSFetchedResultsManager를 사용하는 경우, 그것은 당신의있는 UITableViewController에 대리인 콜백을 구현하기 매우 쉽다. 특히 :

- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller; 
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath; 
- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type; 
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller; 

은 구현을위한 Core Data Books 예에서 RootViewController를 살펴 보자.

이렇게하면 데이터를 완전히 새로 고치지 않고 변경된 부품 만 수정하면됩니다.

관련 문제