나는 (여전히) 난처한 버그가있는 tabbar 앱에서 작업 해왔다.tabbar 앱에서 뷰가 업데이트되지 않음
새 탭으로 이동할 때 앱의 모델 부분에 저장된 데이터는보기에 사용되지 않으므로 부실 정보 (그래프, 숫자 등)가 표시됩니다. 나는 업데이트를 강제하는 두 가지 방법을 시도했다.이 방법은보기에서 [self updateDisplay]
으로 처리된다. (1) 앱 델리게이트에서 UITabBarControllerDelegate
메서드를 사용하여 선택한 탭을 확인한 다음 업데이트 메시지를 보냅니다. 위임 메서드의 본문 부분은 다음과 같습니다.
if (viewController == [tabBarController.viewControllers objectAtIndex:1]) {
NSLog(@"graphViewController selected, graphViewController = %@", graphViewController);
[graphViewController updateDisplay];
}
이것이 내가하는 일입니다. 그러나 NSLog가 updateDisplay가 실행되었음을 확인했지만 디스플레이는 업데이트되지 않습니다.
(2)보기에서 버튼을 눌러 [self updateDisplay]
을 실행하여 디스플레이를 업데이트하십시오. 이것은 효과가 있지만 만족스럽지 않습니다. 이제 재미있는 부분이 있습니다. 아래 로그에서 우리는 (1) 델리게이트 메소드가 호출되었고, (2) graphViewController
이 선택되었고, (3) graphViewController의 updateDisplay 메소드가 호출되었다는 것을 읽었습니다. 큰! 그러나이 시점에서 barGraph
은 null이고 float에서 읽은 레이블을 포함한 디스플레이는 ourLog
으로 업데이트되지 않습니다. 객체 ourLog
은 모델의 일부이며 "디스크"의 파일과 동기화됩니다. (barGraph
은 ourLog
에서 updateDisplay
으로 업데이트됩니다.
계속 이동하면 GraphViewController가 관리하는보기에 "테스트"단추 (6)가 표시되고 updateDisplay
이 호출되면보기가 제대로 업데이트됩니다.
1-5에서 GraphViewController
은 0x4e346e0에있는 반면, 6 - 9에서는 0x4b53c80 이었음에 유의하십시오. 앞뒤로 토글하고 탭 아웃 한 다음 "테스트"버튼을 누르면 항상 16 진수를 얻습니다. 처음에 나는 어쨌든 GraphViewController
의 두 인스턴스가 떠 다니고 있다고 생각했습니다. 그러나 나는 그 클래스의 init
메소드를 오버라이드하여 로깅했다. 한 번만 나타납니다. 그래서 나는 완전히 엉망이되었습니다.
- 짐
UITabBarControllerDelegate 방법이라고]- 1 자기 =
- 2 graphViewController 선택 graphViewController =
- 3 GraphViewController, updateDisplay 자기라는 =
- 4 ourLog :
- 5] updateDisplay, barGraph : (null)
- 6] 테스트가 푸시 됨 GraphViewController, updateDisplay 호출] 5,
- 7 자체 =
- 8 ourLog :
- 9 updateDisplay, barGraph의>
PS. 원래 UIVIew subclass object becomes mysteriously nil in tabbar app에 게시했습니다. 이 문제는 좀 더 일반적이어서 barGraph
은 앱 수명주기의 다양한 시점에서 null이되므로이 글을 새로 게시 할 예정입니다. 어떻게 든 액세스 할 필요가있는 물건은 호출 할 때 액세스 할 필요가 없으므로 다른 방법으로 호출해야합니다. 그러나 그것은 사라지지 않습니다 (나는 또한 dealloc
을 과대 평가했고 barGraph
가 풀려 났음을 발견하지 못했습니다).
부록 1 : BarGraph.
@interface GraphViewController : UIViewController {
BarGraph *barGraph;
}
@property (nonatomic, retain) BarGraph *barGraph;
@property (nonatomic, retain) IBOutlet UIButton *testButton;
- (void) updateDisplay;
- (IBAction) testAction: (id) sender;
@end
, viewDidLoad
ALLOC-inits barGraph의 @implementation
에서 : 여기
이 barGraph의이 GraphViewController에서 만드는 방법입니다
- (void) updateDisplay {
// Check to see where GraphViewController is:
NSLog(@"GraphViewController, updateDisplay called, self = %@", self);
// Get a pointer to the current data to graph
Log *ourLog = [self theDelegate].currentLog
// Log info
NSLog(@"ourLog: %@", ourLog);
NSLog(@"updateDisplay, barGraph: %@", self.barGraph);
// Get the current data out of ourLOg
self.barGraph.data = ourLog.log;
// And ask barGraph to display it
[barGraph setNeedsDisplay];
}
: 마지막으로
- (void) viewDidLoad {
[super viewDidLoad];
NSLog(@"xx:BARGRAPH: alloc-init in viewDidLoad, GraphBar");
barGraph = [[BarGraph alloc] initWithFrame:CGRectMake(15, 140, 289, 130)];
[self.view addSubview:barGraph];
[self updateDisplay];
}
, 여기 updateDisplay
의 구현
부록 2 : viewWillAppear.
이것은 정상적이고 최적의 솔루션처럼 보일 것이다, 그러나이 viewWillAppear
결코 발사하지 다음과 같이
나는 GraphViewController.m
에 viewWillAppear
을 추가했다. 제대로 표시를 갱신하도록 배선되어있는 버튼을 누르면
- (IBAction) testAction: (id) sender {
NSLog(@"test pushed");
[self updateDisplay];
}
: 버튼에 의해 활성화되는 방법 testAction
을 참고. 하지만 물론 iOS가 버튼이 아닌 나를 누르기를 원합니다 :-)
안녕하세요, ProGrmatically GraphViewController barGraph 인스턴스를 만들고 있어요 (barGraph는 다른 응용 프로그램에서 사용한 사용자 지정보기입니다). 위의 관련 코드 중 일부는 부록 1에 게시했습니다. 또한 viewWillAppear을 실험했지만 꼭 호출하지 않는 것 같습니다. 나는 이것을 다시 보게 될 것이다. 감사! –
위의 부록 2에 따라 viewWillAppear를 삽입했습니다. 아아, 절대 불이 나지 않습니다. 만약 내가 그렇게 할 수 있다면, 아마도 내 문제를 해결할 수있을 것이다. –
UITabBarDelegate 메서드에서 수동으로 호출하여 실행할 수 있습니다. 그러나 GraphViewController의 viewWillAppear가 실행되면 이후 updateDisplay를 호출하면 이전 문제가 약간 다른 방식으로 생성됩니다. iOS가이 방법을 호출해야한다고 생각합니다. –