如何在首选项捆绑包中使用PSLinkListCell中的值? [英] How to use the value in PSLinkListCell in preference bundle?

查看:191
本文介绍了如何在首选项捆绑包中使用PSLinkListCell中的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的越狱调整设置首选项. 我成功创建了一个有效开关的首选项包.

I would like to make a preference bundle for my jailbreak tweak. I successfully made a preference bundle with a switch that works.

但是我想要一个选择颜色的设置. 示例:

But I would like a setting to choose color. Example:

         Blue      
Color >  Yellow       
         Green

因此,如果我单击颜色,它将带我到另一个屏幕,要求我选择"蓝色","黄色" "或"绿色" 我看了网上的教程,我认为这是一个PSLinkList.

So if I click on Color, it would bring me to another screen which ask me to choose either "Blue", "Yellow" or "Green" I have looked at tutorials on the net, and I think this is a PSLinkList.

但是我希望我的调整能够读取plist并记录选择的颜色. 我认为它将读取PSLinkListvalidValues,对吗?

But I want my tweak to read the plist and record what color is chosen. I think it would read the validValues of the PSLinkList, am I right?

但是我将使用什么代码来读取plist?

But what code would I use to read the plist?

编辑:Nate帮助我添加了PSListcontroller,但遇到了一个问题:

EDIT: Nate helped me with adding the PSListcontroller but I met one problem:

这是我的清单 http://pastebin.com/uNKzLBrf

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>items</key>
  <array>
    <dict>
      <key>cell</key>
      <string>PSGroupCell</string>
      <key>label</key>
      <string>Main</string>
    </dict>
    <dict>
      <key>cell</key>
      <string>PSSwitchCell</string>
      <key>default</key>
      <true/>
      <key>defaults</key>
      <string>com.junyi00.prefs</string>
      <key>key</key>
      <string>enabled</string>
      <key>label</key>
      <string>Enable</string>
    </dict>
    <dict>
      <key>cell</key>
      <string>PSGroupCell</string>
      <key>label</key>
      <string>Colors</string>
    </dict>
    <dict>
      <key>cell</key>
      <string>PSListLinkCell</string>
      <key>defaults</key>
      <string>com.junyi00.prefs</string>
      <key>detail</key>
      <string>PSListItemsController</string>
      <key>key</key>
      <string>color</string>
      <key>label</key>
      <string>Color</string>
      <key>validTitles</key>
      <array>
        <string>Default</string>
        <string>Random</string>
        <string>Yellow</string>
        <string>Blue</string>
        <string>Red</string>
        <string>Green</string>
      </array>
      <key>validValues</key>
      <array>
        <string>Default</string>
        <string>Random</string>
        <string>Yellow</string>
        <string>Blue</string>
        <string>Red</string>
        <string>Green</string>
      </array>
    </dict>
  </array>
  <key>title</key>
  <string>Flash Color</string>
</dict>
</plist>

帮我这个忙吗?

推荐答案

看看 PreferenceLoader ,现在应该使用该 PreferenceLoader 用于此任务)

Take a look at this older tutorial. (Note: for others reading this, the tutorial does not use PreferenceLoader, which should now be used for this task)

对于您而言,我认为MyAppName.plist应该包含以下内容:

In your case, I think the MyAppName.plist should contain something like this:

    <key>items</key>
    <array>
        <dict>
            <key>cell</key>
            <string>PSLinkListCell</string>
            <key>defaults</key>
            <string>com.mycompany.MyAppName</string>
            <key>detail</key>
            <string>PSListItemsController</string>
            <key>key</key>
            <string>color_pref</string>
            <key>label</key>
            <string>Color</string>
            <key>validTitles</key>
            <array>
                <string>Blue</string>
                <string>Yellow</string>
                <string>Green</string>
            </array>
            <key>validValues</key>
            <array>
                <string>Blue</string>
                <string>Yellow</string>
                <string>Green</string>
            </array>
        </dict>
    </array>

然后您的代码可以读取以下内容:

Which could then be read in by your code like this:

#define PLIST_FILENAME @"/var/mobile/Library/Preferences/com.mycompany.MyAppName.plist"
#define COLOR_PREF @"color_pref"

// an ivar
NSMutableDictionary* preferences;

- (void) initializePreferences {
    NSFileManager* fileManager = [NSFileManager defaultManager];

    // initialize the preferences
    if (![fileManager fileExistsAtPath: PLIST_FILENAME]) {

        // make sure the user settings have default values assigned
        NSDictionary* defaultPrefs = [[NSDictionary alloc] initWithObjectsAndKeys:
                                       @"Yellow", COLOR_PREF,
                                       nil];

        preferences = [[NSMutableDictionary alloc] initWithDictionary: defaultPrefs];
        [preferences writeToFile: PLIST_FILENAME atomically: YES];
    } else {
        preferences = [[NSMutableDictionary alloc] initWithContentsOfFile: PLIST_FILENAME];
    }
}

- (NSString*) colorPref {
    return [preferences valueForKey: COLOR_PREF];
}

我在这里跳过了一些步骤,因为您似乎熟悉将您的越狱应用程序或调整设置添加到Preferences.app .如果这对您不起作用,请发表评论以进行澄清.

I've skipped over some steps here, as it sounds like you're familiar with the general process of adding your jailbreak app, or tweak's, settings to Preferences.app. If this doesn't work for you, post a comment asking for clarification.

这篇关于如何在首选项捆绑包中使用PSLinkListCell中的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆