小编Pab*_*que的帖子

静态表视图的错误

试图在我的应用程序中解决几个场景,我不能让tableViews按照他们应该的方式工作.

我做了像tableView这样的设置,用户在两个可能的设置之间进行选择.每个选项都会导致新的tableView,用户必须选择其中一个可用选项.一旦用户选择了一个,第一个场景中的标签将显示所选的值(也存储为NSUserDefaults).因此,如果我没有弄错,这可以用3个静态tableViews来实现.以下代码是我试图这样做的方式:

初始设置视图控制器:

class SettingsVC2: UITableViewController{
 override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 2
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 1
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    if indexPath.section == 0{

        let cell = tableView.dequeueReusableCellWithIdentifier("office_cell", forIndexPath: indexPath)
        cell.textLabel?.text = "Select your office"
        return cell
} …
Run Code Online (Sandbox Code Playgroud)

uitableview tableview ios swift

6
推荐指数
1
解决办法
415
查看次数

在重新启动应用程序后从SharedPreferences恢复时,设置<String>丢失数据

在android上使用SharedPreference来存储一组字符串.根据我的知识存储和检索它,但是当重新启动应用程序时,一些数据会丢失.字符串是逐个添加的,在添加它之前我检索集合,添加字符串然后再次存储它.

这是我存储它的方式:

Set<String> emptySet = null;
            SharedPreferences prefs = getContext().getSharedPreferences(getContext().getString(R.string.pref_disagree_key), Activity.MODE_PRIVATE);

            String newIdAgreed = getItem(position).getId();

            if (prefs.contains(getContext().getString(R.string.pref_disagree_key))) {

                Set<String> updateSet = prefs.getStringSet(getContext().getString(R.string.pref_disagree_key), emptySet);
                updateSet.add(newIdAgreed);
                SharedPreferences.Editor editor = prefs.edit();
                editor.putStringSet(getContext().getString(R.string.pref_disagree_key), updateSet);
                editor.commit();

            } else {
                Set<String> newSet = new HashSet<String>();
                newSet.add(newIdAgreed);
                SharedPreferences.Editor editor = prefs.edit();
                editor.putStringSet(getContext().getString(R.string.pref_disagree_key), newSet);
                editor.commit();
            }
Run Code Online (Sandbox Code Playgroud)

这就是我得到它的方式:

if (prefsDisagree.contains(getContext().getString(R.string.pref_disagree_key))){
        disagree_set = new HashSet<String>(prefsDisagree.getStringSet(getContext().getString(R.string.pref_disagree_key), emptySet));
        for (String item: disagree_set){
            //stuff done here


        }
}
Run Code Online (Sandbox Code Playgroud)

我看到了一些关于这个主题的类似问题,但没有一个答案解决了我的问题.有任何想法吗?

java android set sharedpreferences

5
推荐指数
1
解决办法
344
查看次数

on(“ click”,event)触发而无需单击

这个主题也有类似的问题,但是他们的答案对我的问题没有帮助。

我试图使用jQuery on("click")来触发一个函数,该函数只是更改被单击的id的类。但是该函数在页面加载时被调用,然后如果您单击应该触发该函数的内容,则它将不会。

这是html:

<nav>
    <ul>
        <li id="all" class="tab-current"><a><span>All Departments</span></a></li>
    </ul>
</nav>
Run Code Online (Sandbox Code Playgroud)

这里的js:

var $all = $("#all");
$all.on("click", function(){
    tabClicked("all");
});
Run Code Online (Sandbox Code Playgroud)

我也尝试过这个:

$all.on("click", tabClicked("all"));
Run Code Online (Sandbox Code Playgroud)

这是函数:

function tabClicked(input){
    //do some stuff here
}
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?先谢谢了!:)

javascript jquery web

0
推荐指数
1
解决办法
693
查看次数