我在应用程序中观察到一个奇怪的趋势:每当显示警报消息时,导航栏按钮标题的值就会更改为其情节提要标题值。这是UIAlertView之一:
上图中可见的标题值100是我的情节提要中存在的值。我已成功将此行按钮的值更改为此行的当前分数:
self.coinsRemainingButton.titleLabel.text = self.coinsRemaining;
一切正常,直到我显示一些警报视图。一旦显示任何UIAlertView,无论当前得分如何,此导航栏按钮的标题都将更改为100。对于前。即使我当前的得分是500,一旦出现警报消息,我的条形按钮的值也会立即更改为100,如上面的屏幕截图所示。
我已经进行了彻底检查,并且自己没有错误地更改了价值。
如果我删除UIAlertView行,一切都会按顺序返回。
谢谢你的时间。
更新1:这是我的UIAlertView代码:
UIAlertView *iapSuccessful = [[UIAlertView alloc] initWithTitle:@"Purchase Successful"
message:@"Congrats!! You just got coins"
delegate:Nil
cancelButtonTitle:@"Ok"
otherButtonTitles: nil];
[iapSuccessful show];
更新2:我找不到解决方案,因此为了变通办法,我想到在显示UIAlertView之后立即通过代码更新我的条形按钮标题:
[iapSuccessful show];
self.coinsRemainingButton.titleLabel.text = self.coinsRemaining;
但UIAlertView仍将强制将条形按钮的标题更改为情节提要值。
我尝试了几种技巧来解决此问题,但是一旦UIAlertView
出现任何提示,titleLabel.text
条形按钮项目的值()就会更改为其情节提要板的值。
我观察到,只有从情节提要中绘制的导航栏对象的值才发生更改。因此,我从情节提要中删除了条形按钮项目,并以编程方式添加了条形按钮,这解决了我的问题:)
如果您需要,这是通过程序添加条形按钮项目的代码:
//Add a custom button as the right bar button item of navigation bar
self.coinsRemainingButton.frame = CGRectMake(0.00f, 0.00f, 72.00f, 37.00f);
[self.coinsRemainingButton setBackgroundImage:[UIImage imageNamed:@"coinsBackground"] forState:UIControlStateNormal];
[self.coinsRemainingButton setTitle:@"100" forState:UIControlStateNormal];
UIBarButtonItem *rightCustomBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.coinsRemainingButton];
self.navigationItem.rightBarButtonItem = rightCustomBarButtonItem;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句