UITableViewCell 和 UISwitches - iPhone SDK [英] UITableViewCell and UISwitches - iPhone SDK

查看:27
本文介绍了UITableViewCell 和 UISwitches - iPhone SDK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为 UITableView 中的每个单元格保存 UISwitch 的状态.有没有办法做到这一点?我正在考虑使用 NSUserDefault 但我不太确定使用给定名称保存值,然后在创建单元格时检索该状态.任何建议都会很好!

谢谢,

凯文

解决方案

你可以试试下面的示例代码;

<预><代码>NSMutableDictionary *dictionay = [[NSMutableDictionary alloc] init];[dictionay setObject:@"1" forKey:@"firstcell"];[dictionay setObject:@"2" forKey:@"secondcell"];..........[[NSUserDefaults standardUserDefaults] setObject:dictionay forKey:@"dictionay"];//检索值;NSMutableDictionary *dictionay = (NSMutableDictionay*)[[NSUserDefaults standardUserDefaults] valueForKey:@"dictionay"];if([[dictionay valueForKey:@"firstcell"] isEqualToString:@"1"])switch1.on = 是;别的switch1.on = NO;........

希望能帮到你.

I am trying to save the states of an UISwitch for each cell in my UITableView. Is there a way to do this? I was thinking of using the NSUserDefault but I'm not too sure about saving the values with a given name and then retrieving that state when the cells are created. Any suggestions would be nice!

Thanks,

Kevin

解决方案

you can try with following sample code;


NSMutableDictionary *dictionay = [[NSMutableDictionary alloc] init];
[dictionay setObject:@"1" forKey:@"firstcell"];
[dictionay setObject:@"2" forKey:@"secondcell"];
.....
.....
[[NSUserDefaults standardUserDefaults] setObject:dictionay forKey:@"dictionay"];

// retrieve values;
NSMutableDictionary *dictionay = (NSMutableDictionay*)[[NSUserDefaults standardUserDefaults] valueForKey:@"dictionay"];
if([[dictionay valueForKey:@"firstcell"] isEqualToString:@"1"])
    switch1.on = YES;
else
    switch1.on = NO;
....
....

I hope, it will help you.

这篇关于UITableViewCell 和 UISwitches - iPhone SDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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