내부에 UIScrollView
이 있고 일부 뷰가 xib 파일에서로드되었습니다.UIScrollView 내의 UIView가 "setNeedDisplay"메서드 호출에도 불구하고 새로 고쳐지지 않았습니다.
UIScrollView
은 세 개만로드합니다. Views
. 현재, 왼쪽 및 오른쪽.
예를 들어, 왼쪽에 하나의보기가 있고 현재 View
오른쪽에 하나의보기가 있습니다. 오른쪽으로 스크롤하면 UIScrollView
은보기를 왼쪽으로 삭제하고 오른쪽으로 스크롤하여 새로운 View
으로 스크롤 한 다음 새로운보기를 새로운 현재 View
오른쪽으로로드합니다.
또한 버튼이 UIScrollView
외부에 있습니다. 그것을 클릭하면 UIScrollView
에 표시된 현재보기의 배경색이 변경됩니다.
잘 작동하지만 때로는 잘 모르겠지만 버튼을 클릭하여보기의 배경색을 잘 변경했지만보기가 새로 고쳐지지 않아 사용자가 변경 사항을 볼 수 없습니다. 배경 색상.
있는 UIScrollView :
container = [[UIScrollView alloc] initWithFrame:frame];
[container setBackgroundColor:[UIColor clearColor]];
[container setCanCancelContentTouches:NO];
[container setClipsToBounds:NO];
[container setShowsHorizontalScrollIndicator:NO];
[container setPagingEnabled:YES];
당신이에서 볼 수 있듯이,
- (void)menuColor:(MenuPickerViewController *)controller didPickOption:(UIView *)button
{
// Get the object containing the data of the product linked with the view.
MyProduct *product = (MyProduct *)[MyProduct getProduct:[_slider getCurrentContentDisplayed]];
// Get the the superview of the button sender to have an access for the attributes of this button (color selected, ...)
ColorButtonMenu *colorView = (ColorButtonMenu *)[button superview];
// Get the current UIView displayed in the UIScrollView
MyView *myView = (MyView *)[self sliderGetViewWithID:[_slider getCurrentContentDisplayed] FromSlider:_slider];
// I check with debugger, the color is well setted
product.color = colorView.color;
// "border" is a view in my xib that I want change its background color.
IFPrint(@"myView.border backgorund color before: %@\n", myView.border.backgroundColor.description);
[myView.border setBackgroundColor:[Utilities colorFromHexString:colorView.color]];
[myView.border setNeedsDisplay];
IFPrint(@"myView.border backgorund color after: %@\n", myView.border.backgroundColor.description);
IFPrint(@"=== DEBUG ===\n");
IFPrint(@"isMainThread ? : %i\n", [NSThread isMainThread]); // Always return YES
IFPrint(@"myView: %@\n", myView); // Always return the address of a valid pointer
IFPrint(@"myView border: %@\n", myView.border); // Always return the address of a valid pointer
IFPrint(@"=============\n\n");
}
그래서 현재보기의 배경색을 변경하는 버튼을 클릭 메서드 호출 메서드의 끝 부분에서, xib
에서로드 된 뷰에서 메서드 setNeedsDisplay
을 호출하려고 시도했지만 다른 뷰는 "테두리"안에 있지만 작동하지 않습니다. 또한 내 메서드는 항상 주 스레드에서 호출됩니다.
어떤 가정입니까?
감사합니다.
편집 :
sliderGetViewWithID로보기 리턴 올바른 볼 경우 물론, 내가 테스트했습니다. 모든 속성이 잘 설정되어 있습니다. 제 의견으로는 정말 새로 고침 문제입니다.
은 (항상) ui (주) 스레드에서 실행되는 menuColor 메소드입니까? –
예, [NSThread isMainThread]가 항상 YES를 반환하기 때문에 이런 경우라고 생각합니다. –
아 로그에 성명이 표시되지 않았습니다. 죄송합니다 –