【问题标题】:Is there a way to define cell values dynamically in InAppSettingsKit?有没有办法在 InAppSettingsKit 中动态定义单元格值?
【发布时间】:2015-01-25 22:33:36
【问题描述】:

出于自然原因,似乎所有内容都是从 Settings.bundle 值中获取其信息的。

但是查看示例 epp 中的“应用程序信息”,它的版本硬编码为“1.0”。在我现在使用的设置屏幕(自制)中,我动态获取并显示它。是否有某种方法可以覆盖那里显示的内容。

使用“单元格说明符的动态值”或您可以覆盖的东西会很棒,这样我就可以编写一个从该单元格的主捆绑包的 CFBundleShortVersionString 获取的方法。我还有其他用例,我想要动态多选值,我从我们的服务器获取和写入,不确定我是否能够使它与这个 api 一起工作。

【问题讨论】:

    标签: ios inappsettings


    【解决方案1】:

    如果我的问题没有错 - 这就是我将自动应用版本添加到 InAppSettingsKit 视图的方法。

    在 Settings.bundle 的 Root.inApp.plist(或 Root.plist)中,将 Type of Version 字段设置为 IASKCustomViewSpecifier:

    <dict>
        <key>DefaultValue</key>
        <string>1.5</string>
        <key>Key</key>
        <string>version</string>
        <key>Title</key>
        <string>VERSION</string>
        <key>Type</key>
        <string>IASKCustomViewSpecifier</string>
    </dict>
    

    接下来为您设置一些代表IASKAppSettingsViewController,例如。在分配点:

    - (IASKAppSettingsViewController*)appSettingsViewController {
        if (!appSettingsViewController) {
            appSettingsViewController = [[IASKAppSettingsViewController alloc] init];
            appSettingsViewController.delegate = self;
        }
        return appSettingsViewController;
    }
    

    现在您可以使用这些委托方法(它们仅在 IASKCustomViewSpecifier 字段中调用):

    - (CGFloat)tableView:(UITableView*)tableView heightForSpecifier:(IASKSpecifier*)specifier;
    - (UITableViewCell*)tableView:(UITableView*)tableView cellForSpecifier:(IASKSpecifier*)specifier;
    

    这是我的实现:

    - (UITableViewCell*)tableView:(UITableView*)tableView cellForSpecifier:(IASKSpecifier*)specifier {
        NSString *identifier = [NSString stringWithFormat:@"%@-%ld-%d", specifier.type, (long)specifier.textAlignment, !!specifier.subtitle.length];
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
        }
        if ([specifier.key isEqualToString:@"version"]) {
            [cell.textLabel setText:specifier.title];
            [cell.detailTextLabel setText:[NSString stringWithFormat:@"%@ (%@)", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"], [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]]];
        }
        NSLog(@"Cell key: %@", specifier.key);
        return cell;
    }
    - (CGFloat)tableView:(UITableView*)tableView heightForSpecifier:(IASKSpecifier*)specifier {
        return 44.0f;
    }
    

    结果如下:

    【讨论】:

      猜你喜欢
      • 2012-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多