無法在lMenu_time(這是一個UILabel)最初設置後更改文本。 執行回調,我測試了這個,但文字不會改變。 ??我正在傳遞指針並對UILabel進行調整。 ??UILabel文字不變?
lMenu_time和許多其他定義在頭文件中。 (這裏不可見)
UILabel *lMenu_time;
...
-(void) NewNumber: (UIButton*) btn {
if (btn.tag == 102){
iTime++;
[lbl setText:@"time"];
if(iTime > 20){iTime=1;}
[lMenu_time setText:[NSString stringWithFormat: @"Hold: %d", iTime]];
}
....
}
- (void) menuItem: (UIView*)vMenu menuButton:(UIButton*)bMenu menuLabel: (UILabel*)lMenu menuPosX: (double)posX menuLenX: (double)lenX menuTagNum: (int)tagNum menuText: (NSString*)txtMenu{
bMenu = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[bMenu setFrame:CGRectMake(posX,0,lenX,25)];
[bMenu setTag: tagNum];
[bMenu addTarget:self action:@selector(NewNumber:) forControlEvents:UIControlEventTouchUpInside];
[vMenu addSubview:bMenu];
lMenu = [[[UILabel alloc] initWithFrame:CGRectMake(posX,0,lenX,25)] retain];
[lMenu setBackgroundColor:[UIColor lightGrayColor]];
[lMenu setText:[NSString stringWithFormat: txtMenu]];
[lMenu setFont:[UIFont systemFontOfSize:14 ]];
[lMenu setTextAlignment:UITextAlignmentCenter];
[vMenu addSubview: lMenu];
}
- (void) menuBuild{
pSelf = self;
theString = @"";
UIView *vMenu = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,25)];
[pSelf.view addSubview:vMenu];
[vMenu setBackgroundColor:[UIColor grayColor]];
iTime = 2;
[self menuItem:vMenu menuButton:bMenu_time menuLabel:lMenu_time menuPosX:240+20 menuLenX:60 menuTagNum:102 menuText:[NSString stringWithFormat: @"Hold: %d", iTime]];
...
}
我意識到它是零。不知道爲什麼它是空的。不知道它爲什麼是...即使我做了UILabel「alloc」,我是否需要做一個「保留」? – jdl
lMenu_time是視圖控制器的'@屬性'嗎? – Tim
從代碼中你可以看到我在那裏生成了標籤。 – jdl