서브 클래 싱 된 UIToolBar에 레이블을 설정하려고합니다. 먼저 라벨을 생성 한 다음 UIBarButtonItem으로 변환하고 툴바로 설정하지만 툴바는 그냥 비어 있습니다. 여기레이블이 UIToolBar에 표시되지 않습니다.
내 서브 클래 싱 된 도구 모음
NSMutableArray *items = [[NSMutableArray alloc] init];
// prep the total label
_totalLabel = [[UILabel alloc] init];
_totalLabel.font = [_totalLabel.font fontWithSize:15];
_totalLabel.textColor = [UIColor whiteColor];
_totalLabel.text = NSLocalizedString(@"TOTAL", nil);
_totalLabel.frame = CGRectMake(0, 0, 100, 44);
_totalLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin;
_totalLabel.layer.borderWidth = 2;
_totalLabel.layer.borderColor = [UIColor greenColor].CGColor;
_totalLabel.backgroundColor = [UIColor clearColor];
UIBarButtonItem *spacer2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[items addObject:spacer2];
UIBarButtonItem *total = [[UIBarButtonItem alloc] initWithCustomView:_totalLabel];
[items addObject:total];
[self setItems:items];
내 init 메소드에 무슨 잘못 어떤 생각이 내 코드입니까?
일종. 내 init 메서드는 [self setLabels]를 호출하고 위의 코드는 해당 메서드에 있습니다. – JMD
나중에 뷰의 수명주기에서이 작업을 수행해야합니다. 하위 메서드 등은 init 메서드가 호출 될 때 설정되지 않습니다. 보기 컨트롤러에서 viewDidLoad :의 툴바에있는 setupLables 메소드를 호출하십시오. –