1
我在一个简单的“基于点”的应用程序工作。UISlider核心数据编程
在设置下,用户设置使用滑块获取“goodie”所需的点数。
-(IBAction) sliderChanged: (id)sender {
UISlider *slider = (UISlider *) sender;
int progressAsInt =(int)(slider.value +0.5);
NSString *newText = [[NSString alloc] initWithFormat:@"%d",progressAsInt];
sliderLabel.text = newText;
[newText release];
这工作得很好,但如何让我的滑块值存储在我的核心数据模型,以及如何使我的幻灯播放存储的值时,视图的负荷。
希望你能帮助我:-D
嘿gerry3我发现我的错误。我从来没有把我的TOD对象在我settingsViewController,有:
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:[NSEntityDescription
entityForName:@"ToDo" inManagedObjectContext:_context]];
NSError *error = nil;
NSArray *array = [_context executeFetchRequest:request error:&error];
if (array == nil)
{
// Deal with error...
}
if(array.count > 0){
toDo = [array objectAtIndex:0];
} else { // no one to fetch - generate one
toDo = [NSEntityDescription
insertNewObjectForEntityForName:@"ToDo"
inManagedObjectContext:_context];
[toDo retain];
你的代码的工作就像一个魅力.....
感谢 斯科夫
谢谢gerry3,但如果我收我的应用程序,并重新启动应用程序时,滑块go's回到1,如果我添加 - (空)保存{ \t INT progressAsInt =( int)(pointSlider.value +0.5); \t toDo.goodiesPoints = [NSNumber numberWithInteger:progressAsInt]; – Skovie 2011-02-09 21:53:12