UIAlertView导致更改导航栏按钮的titleLabel

时间:2013-11-20 13:15:03

标签: ios uialertview

我在我的应用程序中观察到一个奇怪的趋势:每当显示警告消息时,导航栏按钮的标题值将更改为其故事板标题值。这是UIAlertView之一:

navigation bar button title getting changed by alert view

上图中可见的标题值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仍然强制将条形按钮的标题更改为故事板值。

2 个答案:

答案 0 :(得分:2)

我尝试了几个技巧来解决这个问题但是只要出现任何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;

答案 1 :(得分:1)

从故事板中删除按钮的标题,它解决了问题

相关问题