NSUserDefaults没有保存(NSUserDefaults not saving)
我正在尝试保存一些数据,并在不同控制器的tableview中调用它,但它不起作用。 我在某种程度上也失去了一个变量值,就像我在视图控制器中更改它时类别var变回零一样。
在我的NewEntry.m中,我有:
-(IBAction)saveButton:(id)sender { int i = selectedSegment.selectedSegmentIndex; NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; [userDefaults setInteger:i forKey:@"category"]; [userDefaults synchronize]; if (selectedSegment.selectedSegmentIndex == 0) { [userDefaults setObject:titlefield.text forKey:@"titletexthomework"]; [userDefaults setObject:detailstextfield.text forKey:@"detailshomework"]; } else if(selectedSegment.selectedSegmentIndex == 1) { [userDefaults setObject:titlefield.text forKey:@"titletextprojects"]; [userDefaults setObject:detailstextfield.text forKey:@"detailsprojects"]; } else if (selectedSegment.selectedSegmentIndex == 2){ [userDefaults setObject:titlefield.text forKey:@"titletextappointments"]; [userDefaults setObject:detailstextfield.text forKey:@"detailsappointments"]; } else if (selectedSegment.selectedSegmentIndex == 3){ [userDefaults setObject:titlefield.text forKey:@"titletextevents"]; [userDefaults setObject:detailstextfield.text forKey:@"detailsevents"]; } else if (selectedSegment.selectedSegmentIndex == 4){ [userDefaults setObject:titlefield.text forKey:@"titletexttodolist"]; [userDefaults setObject:detailstextfield.text forKey:@"detailstodolist"]; } [userDefaults synchronize]; NSLog(@"selected segment %i", i); }
然后在我的Projects.m中我有:
-(void)viewDidLoad { [super viewDidLoad]; categoryselected = [[NSUserDefaults standardUserDefaults] integerForKey:@"category"]; NSLog(@"category selected %i", categoryselected); titlestring = [[NSUserDefaults standardUserDefaults] objectForKey:@"titletextprojects"]; detailsstring = [[NSUserDefaults standardUserDefaults] objectForKey:@"detailsprojects"]; tabledata = [[NSArray alloc] initWithObjects:titlestring, nil]; tablesubtitles = [[NSArray alloc] initWithObjects:detailsstring, nil]; } //------------------------------------------------------- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; { UITableViewCell *cell = nil; cell = [tableView dequeueReusableCellWithIdentifier:@"projectscell"]; if(cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"projectscell"]; } cell.textLabel.text = [tabledata objectAtIndex:indexPath.row]; cell.detailTextLabel.text = [tablesubtitles objectAtIndex:indexPath.row]; cell.textLabel.font = [UIFont systemFontOfSize:14.0]; cell.textLabel.backgroundColor = [ UIColor clearColor ]; cell.detailTextLabel.backgroundColor = [UIColor clearColor]; return cell; }
** * ** * * 更新 * ** * ** * ** * ** * *
我将填充表的部分更改为静态字符串,如下所示:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; { tabl = [[NSArray alloc] initWithObjects:@"hello", nil]; NSLog(@"tabledata %@", tabledata ); tab = [[NSArray alloc] initWithObjects:@"hello2", nil]; NSLog(@"details %@", tablesubtitles); UITableViewCell *cell = nil; cell = [tableView dequeueReusableCellWithIdentifier:@"projectscell"]; if(cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"projectscell"]; } cell.textLabel.text = [tabl objectAtIndex:indexPath.row]; cell.detailTextLabel.text = [tab objectAtIndex:indexPath.row]; cell.textLabel.font = [UIFont systemFontOfSize:14.0]; cell.textLabel.backgroundColor = [ UIColor clearColor ]; cell.detailTextLabel.backgroundColor = [UIColor clearColor];
表格仍显示空白。 谢谢您的帮助。
I'm trying to save some data and call it back in a tableview from a different controller but it doesn't working. I'm somehow losing a variable value as well, like the category var changes back to zero when I change it in a view controller, any of them.
In my NewEntry.m I have:
-(IBAction)saveButton:(id)sender { int i = selectedSegment.selectedSegmentIndex; NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; [userDefaults setInteger:i forKey:@"category"]; [userDefaults synchronize]; if (selectedSegment.selectedSegmentIndex == 0) { [userDefaults setObject:titlefield.text forKey:@"titletexthomework"]; [userDefaults setObject:detailstextfield.text forKey:@"detailshomework"]; } else if(selectedSegment.selectedSegmentIndex == 1) { [userDefaults setObject:titlefield.text forKey:@"titletextprojects"]; [userDefaults setObject:detailstextfield.text forKey:@"detailsprojects"]; } else if (selectedSegment.selectedSegmentIndex == 2){ [userDefaults setObject:titlefield.text forKey:@"titletextappointments"]; [userDefaults setObject:detailstextfield.text forKey:@"detailsappointments"]; } else if (selectedSegment.selectedSegmentIndex == 3){ [userDefaults setObject:titlefield.text forKey:@"titletextevents"]; [userDefaults setObject:detailstextfield.text forKey:@"detailsevents"]; } else if (selectedSegment.selectedSegmentIndex == 4){ [userDefaults setObject:titlefield.text forKey:@"titletexttodolist"]; [userDefaults setObject:detailstextfield.text forKey:@"detailstodolist"]; } [userDefaults synchronize]; NSLog(@"selected segment %i", i); }
then in my Projects.m I have:
-(void)viewDidLoad { [super viewDidLoad]; categoryselected = [[NSUserDefaults standardUserDefaults] integerForKey:@"category"]; NSLog(@"category selected %i", categoryselected); titlestring = [[NSUserDefaults standardUserDefaults] objectForKey:@"titletextprojects"]; detailsstring = [[NSUserDefaults standardUserDefaults] objectForKey:@"detailsprojects"]; tabledata = [[NSArray alloc] initWithObjects:titlestring, nil]; tablesubtitles = [[NSArray alloc] initWithObjects:detailsstring, nil]; } //------------------------------------------------------- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; { UITableViewCell *cell = nil; cell = [tableView dequeueReusableCellWithIdentifier:@"projectscell"]; if(cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"projectscell"]; } cell.textLabel.text = [tabledata objectAtIndex:indexPath.row]; cell.detailTextLabel.text = [tablesubtitles objectAtIndex:indexPath.row]; cell.textLabel.font = [UIFont systemFontOfSize:14.0]; cell.textLabel.backgroundColor = [ UIColor clearColor ]; cell.detailTextLabel.backgroundColor = [UIColor clearColor]; return cell; }
*******UPDATE**************
I Changed the part that populates the table to static string like this:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; { tabl = [[NSArray alloc] initWithObjects:@"hello", nil]; NSLog(@"tabledata %@", tabledata ); tab = [[NSArray alloc] initWithObjects:@"hello2", nil]; NSLog(@"details %@", tablesubtitles); UITableViewCell *cell = nil; cell = [tableView dequeueReusableCellWithIdentifier:@"projectscell"]; if(cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"projectscell"]; } cell.textLabel.text = [tabl objectAtIndex:indexPath.row]; cell.detailTextLabel.text = [tab objectAtIndex:indexPath.row]; cell.textLabel.font = [UIFont systemFontOfSize:14.0]; cell.textLabel.backgroundColor = [ UIColor clearColor ]; cell.detailTextLabel.backgroundColor = [UIColor clearColor];
And the table still shows up blank. Thanks For the help.
原文:https://stackoverflow.com/questions/9417651
最满意答案
最好使用SessionRenderer。 查看我的ICEfaces书籍示例( http://icecube-on-icefusion.googlecode.com/ )并搜索progressDialog标签以获取示例。 或者书中的第244ff页。
It would be better to use the SessionRenderer. Have a look at my ICEfaces book examples (http://icecube-on-icefusion.googlecode.com/) and search for the progressDialog tag for an example. Or page 244ff in the book.
相关问答
更多-
最好使用SessionRenderer。 查看我的ICEfaces书籍示例( http://icecube-on-icefusion.googlecode.com/ )并搜索progressDialog标签以获取示例。 或者书中的第244ff页。 It would be better to use the SessionRenderer. Have a look at my ICEfaces book examples (http://icecube-on-icefusion.googlecode.com/ ...
-
Richfaces和Icefaces不会在一起。 但是,由于您使用的是JSF 2(我猜这是Richfaces 4),您可以同时使用Richfaces和Primefaces。 实际上,使用Primefaces只需要将jar添加到CLASSPATH中。 Richfaces and Icefaces do not go together. However, since you are using JSF 2 (so Richfaces 4 I guess) you can use both Richfaces a ...
-
创建连接bean和Facelets的ICEfaces应用程序示例(Creating ICEfaces application example connecting beans and Facelets)[2022-03-24]
完整的示例代码列表,您可以在这里找到http://anonsvn.icesoft.org/repo/icefaces3/trunk/icefaces/samples Complete list of sample codes you can find here http://anonsvn.icesoft.org/repo/icefaces3/trunk/icefaces/samples -
使用库存JSF以及扩展它的大多数其他框架,您需要为Ajax请求指定更新区域。 ICEfaces计算出需要在服务器端应用的差异和变化。 因此,如果您不希望,则无需指定特定的更新区域。 但是,如果您需要,该选项仍可供您使用。 With stock JSF and with most other frameworks that extend it, you need to specify the update region for Ajax requests. ICEfaces figures out the d ...
-
您可以使用or或|| 例如,在表达语言中 style="display: #{bean.isBool1() or bean.isBool2() ? 'inline' : 'none'}". 以下是Java EE 6和Java EE 7的EL运算符概述。 You can use either or or || in Expression Language, for example style="display: #{bean.isBool1() or bean.isBool2() ? 'inline' : ...
-
如上所述: 如何使错误页面(http 500)在IceFaces中运行? 。 根据http://wiki.icefaces.org/display/ICE/Configuration ,可以通过在web.xml中将autorender context参数设置为false来禁用此功能。 但是,您需要在每个icefaces表单上明确地启用此行为(否则会出现错误)。 As stated here: how to make error page (http 500) work in IceFaces?. This ...
-
IceFaces 3纠正了这个错误,不再需要解决方法。 IceFaces 3 corrected this bug, no need anymore for a workaround.
-
h:selectBooleanCheckbox将使用ace / f:ajax,ice只有partialSubmit =“true” h:selectBooleanCheckbox will working with ace/f:ajax, ice only have partialSubmit="true"
-
我们尝试了Icefaces(在JSF 1.2模式下)和Atmosphere / Comet with Primefaces。 Icefaces推出工作出色的开箱即用。 我们无法使Atmosphere工作(在Primefaces中),但这可能是因为我们尝试了最新的(0.6)版本,Primefaces还不支持它 - 所以现在我们正在等待更新版本(它是承诺它将成为p:dataTable被重写之后的下一个重要特征)。 在我们的例子中,推送不是演示中的关键元素,我们可以轻松地使用轮询而不是真正的推送解决方案。 Ice ...
-
ICEfaces SelectOneMenu ValueChangeListener不工作(ICEfaces SelectOneMenu ValueChangeListener not working)[2022-03-07]
将partialSubmit="true"添加到组件,完全如组件引用底部附近所示。 Add partialSubmit="true" to the component, exactly as demonstrated somewhere near the bottom of their component reference.