1

我有一个UITabBar带有 5 个选项卡的项目。
我正在制作 2 个目标版本:免费版和付费版。

在免费版本中,当用户尝试导航到标签项索引 3 或 4 时,UIAlertView应该会出现一条基本消息,例如:

你想升级吗?
是/取消

按下Cancel按钮时,视图应该转到第一个视图控制器。
我该怎么做?

另外,我的下一个问题(我知道我应该在 Stack 中提出另一个问题)是如何防止UIAlertView出现在付费版本中?

我已经UIAlertView为选项卡项目 3 和 4 使用按钮,但我不希望这样。

这两个目标运行良好,我使用以下代码:

- (IBAction)openAlert:(id)sender
{
#ifdef FREE

    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"Attention" 
                                                       message:@"Choose option" 
                                                      delegate:self
                                             cancelButtonTitle:@"Cancel"
                                             otherButtonTitles:@"Download Full version", nil];
    [alertView show];

#endif
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex ==1) {
        [[UIApplication sharedApplication]openURL:[NSURL URLWithString:[NSString  stringWithFormat:@"http://***.com"]]];
    }
}

任何帮助,将不胜感激。

4

3 回答 3

0

对于第一个问题,您需要使用警报视图中单击的按钮索引的值,(void)alertView: (UIAlertView )alertView clickedButtonAtIndex:(NSInteger)buttonIndex并检查按下按钮的索引是否与取消按钮的索引相同。然后,您可以以编程方式按下所需视图的选项卡并转到该视图。

在加载弹出警报之前,请检查应用程序的状态,付费或免费。您可以通过两种方式进行检查,一种是将应用程序购买状态存储在设备上NSUserDefaults,另一种是通过服务器身份验证,尽管服务器身份验证会阻碍应用程序的使用,因为它需要一些时间是时候从服务器获取响应了,在没有网络连接的情况下,用户将无法使用应用程序的付费功能。

如果应用程序具有所需的付费状态,只需让付费选项卡中的视图加载,否则只显示黑屏。

您可以在付费选项卡的视图控制器中实现此检查。在viewWillAppear中,执行此检查以获取付款状态,然后如果应用程序不是付费应用程序,则显示黑色视图并显示警报消息。否则,如果该应用程序已付费,则业务照常进行。

于 2013-12-12T12:26:27.150 回答
0

将您的 appdelegate 设置为您的标签栏控制器的代表,并在 appdelegate 或任何地方执行此工作

  1. 当用户按下取消按钮然后调用

[yourTabbarController setSelectedIndex:0]

  1. 在以下委托方法中编写代码以避免在特定版本中出现警报(付费/免费)
  • (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
于 2013-12-12T12:04:13.087 回答
0

在取消时,要移动到另一个UIViewController,您只需更改self.tabBarController对象的setSelectedIndex

例子:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    switch (buttonIndex) {
        case 0:
            //Cancel button was clicked
            [self.tabBarController setSelectedIndex:0];
        break;
        case 1:
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString  stringWithFormat:@"http://***.com"]]];
        break;
    }
}

至于免费与付费,它是基于意见的。
一种基本的方法是使用NSUserDefaults记住应用程序是免费版本还是付费版本并相应地处理您的逻辑。

于 2013-12-12T12:14:42.323 回答