我已經創建了多個UILabel,每個都有自己的.tag值。然後,我嘗試使用另一個類的NSString填充UILabel,該類調用的方法來自使用.tag設置UILabels的方法。但是,當我嘗試訪問我的調試部分中的標籤時顯示標籤爲空,文本從未設置。使用標記符號訪問UILabel
這就是我的方法看起來像被稱爲從另一個calss。
- (void) SymbolButtonPressed:(NSString *)selectedString {
UILabel *label = (UILabel *)[cutField viewWithTag:currentlySelectedTag];
[label setText:selectedString];
}
標籤時我調試的代碼= NULL ...我不知道爲什麼
的要求,這是我怎麼加標籤
axesView = [[UIView alloc] init];
axesView.frame = CGRectMake(0.0, 0.0, scrollWidth+10, 77.0);
cutField = [[UILabel alloc] initWithFrame:CGRectMake((i*40)+2, 35, 40, 40)];
cutField.textColor = [UIColor blackColor];
[cutField setTextAlignment:NSTextAlignmentCenter];
cutField.font = [UIFont fontWithName:@"Helvetica" size:20];
cutField.backgroundColor=[UIColor whiteColor];
cutField.layer.borderColor = [[UIColor colorWithRed:colorController.grRed/255.0 green:colorController.grGreen/255.0 blue:colorController.grBlue/255.0 alpha:1.0] CGColor];
cutField.layer.borderWidth = 0.5f;
[axView addSubview:cutField];
是標籤,你正在尋找,cutField的子視圖? – thbonk
你試過了嗎(UILabel *)[self.view viewWithTag:currentlySelectedTag];?也許你正在向self.view添加提到的UILabel。你可以在你添加標籤的地方發佈代碼嗎? – vburojevic
什麼是cutField?如果您試圖通過標籤訪問的視圖與具有SymbolButtonPressed:方法的視圖不在同一個控制器中,那麼您需要先獲取對其他控制器的引用,然後才能訪問其任何視圖。 – rdelmar