Skip to content
This repository has been archived by the owner on May 18, 2020. It is now read-only.

Commit

Permalink
fix load data
Browse files Browse the repository at this point in the history
  • Loading branch information
Natalia Bilogrud committed Sep 20, 2012
1 parent dd099ca commit 6d4117c
Show file tree
Hide file tree
Showing 22 changed files with 588 additions and 97 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 27 additions & 16 deletions RandomTimerApp/RandomTimerApp.xcodeproj/project.pbxproj
Expand Up @@ -12,12 +12,13 @@
6E86832E16076D43007A7F58 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6E86832D16076D43007A7F58 /* Foundation.framework */; };
6E86833016076D43007A7F58 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6E86832F16076D43007A7F58 /* CoreGraphics.framework */; };
6E86833216076D43007A7F58 /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6E86833116076D43007A7F58 /* CoreData.framework */; };
6E86833816076D43007A7F58 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 6E86833616076D43007A7F58 /* InfoPlist.strings */; };
6E86833E16076D44007A7F58 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 6E86833D16076D44007A7F58 /* AppDelegate.m */; };
6E86834116076D44007A7F58 /* RandomTimerApp.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 6E86833F16076D44007A7F58 /* RandomTimerApp.xcdatamodeld */; };
6E86834B16076E67007A7F58 /* RandomTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6E86834A16076E67007A7F58 /* RandomTableViewController.m */; };
6E86834F16076F2A007A7F58 /* GeneratedData.m in Sources */ = {isa = PBXBuildFile; fileRef = 6E86834E16076F2A007A7F58 /* GeneratedData.m */; };
6E86835616077493007A7F58 /* Generator.m in Sources */ = {isa = PBXBuildFile; fileRef = 6E86835516077493007A7F58 /* Generator.m */; };
6EAFE897160B6D8700DFB58A /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 6EAFE899160B6D8700DFB58A /* Localizable.strings */; };
6EAFE89C160B71A900DFB58A /* SettingViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EAFE89B160B71A900DFB58A /* SettingViewController.m */; };
6ED98254160A32A30070ADEF /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 6ED98253160A32A30070ADEF /* main.m */; };
6ED98259160A32E60070ADEF /* CoreDataManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 6ED98258160A32E60070ADEF /* CoreDataManager.m */; };
6ED98275160A32F20070ADEF /* NSObject+SBJson.m in Sources */ = {isa = PBXBuildFile; fileRef = 6ED9825D160A32F20070ADEF /* NSObject+SBJson.m */; };
Expand All @@ -33,8 +34,6 @@
6ED9827F160A32F20070ADEF /* SBJsonUTF8Stream.m in Sources */ = {isa = PBXBuildFile; fileRef = 6ED98272160A32F20070ADEF /* SBJsonUTF8Stream.m */; };
6ED98280160A32F20070ADEF /* SBJsonWriter.m in Sources */ = {isa = PBXBuildFile; fileRef = 6ED98274160A32F20070ADEF /* SBJsonWriter.m */; };
6ED98284160A331F0070ADEF /* Connect.m in Sources */ = {isa = PBXBuildFile; fileRef = 6ED98283160A331F0070ADEF /* Connect.m */; };
6ED98288160A33400070ADEF /* SettingViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6ED98286160A33400070ADEF /* SettingViewController.m */; };
6ED98289160A33400070ADEF /* SettingViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6ED98287160A33400070ADEF /* SettingViewController.xib */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -45,7 +44,6 @@
6E86832F16076D43007A7F58 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
6E86833116076D43007A7F58 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; };
6E86833516076D43007A7F58 /* RandomTimerApp-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "RandomTimerApp-Info.plist"; sourceTree = "<group>"; };
6E86833716076D43007A7F58 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
6E86833B16076D44007A7F58 /* RandomTimerApp-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RandomTimerApp-Prefix.pch"; sourceTree = "<group>"; };
6E86833C16076D44007A7F58 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
6E86833D16076D44007A7F58 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
Expand All @@ -56,6 +54,9 @@
6E86834E16076F2A007A7F58 /* GeneratedData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedData.m; sourceTree = "<group>"; };
6E86835416077493007A7F58 /* Generator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Generator.h; sourceTree = "<group>"; };
6E86835516077493007A7F58 /* Generator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Generator.m; sourceTree = "<group>"; };
6EAFE898160B6D8700DFB58A /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
6EAFE89A160B6D9100DFB58A /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ru; path = ru.lproj/Localizable.strings; sourceTree = "<group>"; };
6EAFE89B160B71A900DFB58A /* SettingViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SettingViewController.m; sourceTree = "<group>"; };
6ED98253160A32A30070ADEF /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = "Supporting files/main.m"; sourceTree = "<group>"; };
6ED98256160A32C90070ADEF /* CommonConst.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CommonConst.h; path = "Supporting files/CommonConst.h"; sourceTree = "<group>"; };
6ED98257160A32E60070ADEF /* CoreDataManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CoreDataManager.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -88,8 +89,6 @@
6ED98282160A331F0070ADEF /* Connect.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Connect.h; sourceTree = "<group>"; };
6ED98283160A331F0070ADEF /* Connect.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Connect.m; sourceTree = "<group>"; };
6ED98285160A33400070ADEF /* SettingViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SettingViewController.h; sourceTree = "<group>"; };
6ED98286160A33400070ADEF /* SettingViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SettingViewController.m; sourceTree = "<group>"; };
6ED98287160A33400070ADEF /* SettingViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = SettingViewController.xib; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -138,6 +137,7 @@
6E86833316076D43007A7F58 /* RandomTimerApp */ = {
isa = PBXGroup;
children = (
6EAFE894160B6D6000DFB58A /* Resources */,
6ED9825A160A32F20070ADEF /* External */,
6E86834C16076F12007A7F58 /* Models */,
6E86834816076D93007A7F58 /* Controllers */,
Expand All @@ -147,18 +147,17 @@
6ED98258160A32E60070ADEF /* CoreDataManager.m */,
6E86833F16076D44007A7F58 /* RandomTimerApp.xcdatamodeld */,
6E86833416076D43007A7F58 /* Supporting Files */,
6E12AA2C160A4EA6009E6085 /* Settings.bundle */,
);
path = RandomTimerApp;
sourceTree = "<group>";
};
6E86833416076D43007A7F58 /* Supporting Files */ = {
isa = PBXGroup;
children = (
6E12AA2C160A4EA6009E6085 /* Settings.bundle */,
6ED98256160A32C90070ADEF /* CommonConst.h */,
6ED98253160A32A30070ADEF /* main.m */,
6E86833516076D43007A7F58 /* RandomTimerApp-Info.plist */,
6E86833616076D43007A7F58 /* InfoPlist.strings */,
6E86833B16076D44007A7F58 /* RandomTimerApp-Prefix.pch */,
);
name = "Supporting Files";
Expand All @@ -168,8 +167,7 @@
isa = PBXGroup;
children = (
6ED98285160A33400070ADEF /* SettingViewController.h */,
6ED98286160A33400070ADEF /* SettingViewController.m */,
6ED98287160A33400070ADEF /* SettingViewController.xib */,
6EAFE89B160B71A900DFB58A /* SettingViewController.m */,
6E86834916076E67007A7F58 /* RandomTableViewController.h */,
6E86834A16076E67007A7F58 /* RandomTableViewController.m */,
);
Expand All @@ -187,6 +185,14 @@
path = Models;
sourceTree = "<group>";
};
6EAFE894160B6D6000DFB58A /* Resources */ = {
isa = PBXGroup;
children = (
6EAFE899160B6D8700DFB58A /* Localizable.strings */,
);
path = Resources;
sourceTree = "<group>";
};
6ED9825A160A32F20070ADEF /* External */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -272,6 +278,7 @@
hasScannedForEncodings = 0;
knownRegions = (
en,
ru,
);
mainGroup = 6E86831C16076D43007A7F58;
productRefGroup = 6E86832816076D43007A7F58 /* Products */;
Expand All @@ -288,9 +295,8 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
6E86833816076D43007A7F58 /* InfoPlist.strings in Resources */,
6ED98289160A33400070ADEF /* SettingViewController.xib in Resources */,
6E12AA2D160A4EA6009E6085 /* Settings.bundle in Resources */,
6EAFE897160B6D8700DFB58A /* Localizable.strings in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -321,19 +327,20 @@
6ED9827F160A32F20070ADEF /* SBJsonUTF8Stream.m in Sources */,
6ED98280160A32F20070ADEF /* SBJsonWriter.m in Sources */,
6ED98284160A331F0070ADEF /* Connect.m in Sources */,
6ED98288160A33400070ADEF /* SettingViewController.m in Sources */,
6EAFE89C160B71A900DFB58A /* SettingViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */

/* Begin PBXVariantGroup section */
6E86833616076D43007A7F58 /* InfoPlist.strings */ = {
6EAFE899160B6D8700DFB58A /* Localizable.strings */ = {
isa = PBXVariantGroup;
children = (
6E86833716076D43007A7F58 /* en */,
6EAFE898160B6D8700DFB58A /* en */,
6EAFE89A160B6D9100DFB58A /* ru */,
);
name = InfoPlist.strings;
name = Localizable.strings;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */
Expand Down Expand Up @@ -361,6 +368,8 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 5.1;
OTHER_CFLAGS = "-DDEBUGGING";
OTHER_CPLUSPLUSFLAGS = "$(OTHER_CFLAGS)";
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand Down Expand Up @@ -394,6 +403,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "RandomTimerApp/RandomTimerApp-Prefix.pch";
INFOPLIST_FILE = "RandomTimerApp/RandomTimerApp-Info.plist";
OTHER_CPLUSPLUSFLAGS = "$(OTHER_CFLAGS)";
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
Expand All @@ -405,6 +415,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "RandomTimerApp/RandomTimerApp-Prefix.pch";
INFOPLIST_FILE = "RandomTimerApp/RandomTimerApp-Info.plist";
OTHER_CPLUSPLUSFLAGS = "$(OTHER_CFLAGS)";
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
Expand Down
2 changes: 2 additions & 0 deletions RandomTimerApp/RandomTimerApp/AppDelegate.m
Expand Up @@ -43,11 +43,13 @@ - (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
[[[self mainController] generator] stopGenerator];
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
[[[self mainController] generator] startGenerator];
}

- (void)applicationDidBecomeActive:(UIApplication *)application
Expand Down
Expand Up @@ -7,11 +7,12 @@
//

#import <UIKit/UIKit.h>
#import "Generator.h"

@interface RandomTableViewController : UITableViewController< NSFetchedResultsControllerDelegate, NSURLConnectionDataDelegate>

@property (retain, nonatomic) UITableView* tableRandomData;
@property (retain, nonatomic) NSFetchedResultsController* fetchResult;
//@property (retain, nonatomic) NSMutableArray* listGeneratedData;
@property (assign, nonatomic) BOOL useLocal;
@property (retain, nonatomic) Generator* generator;
@end
Expand Up @@ -13,7 +13,6 @@
#import "CoreDataManager.h"
#import "SettingViewController.h"
@interface RandomTableViewController ()
@property (retain, nonatomic) Generator* generator;
- (void)genarate;
- (void)showSettings;
@end
Expand Down Expand Up @@ -48,7 +47,7 @@ - (void)initFetchResult
NSError *err;
BOOL success = [fetchResult performFetch:&err];
if (!success) {
NSLog(@"fail performFetch");
DBLog(@"fail performFetch");
}

[fetchRequest release];
Expand All @@ -71,9 +70,9 @@ - (void)viewDidLoad
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillEnterForeground:) name:UIApplicationWillEnterForegroundNotification object:app];

[self initFetchResult];
[self.tableView reloadData];
[self genarate];

[self performSelector:@selector(genarate) withObject:nil afterDelay:2];

UIBarButtonItem *right = [[UIBarButtonItem alloc] initWithTitle: NSLocalizedString(@"Setting", @"") style:UIBarButtonItemStylePlain target:self action:@selector(showSettings)];

self.navigationItem.rightBarButtonItem = right;
Expand Down Expand Up @@ -110,16 +109,14 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
- (void)genarate
{
self.generator = [[Generator alloc] init];
[self.generator doGenerate];
[self.generator startGenerator];
[self.generator release];
}

- (void) showSettings
{
NSLog(@"setting button");
SettingViewController* settingViewController = [[[SettingViewController alloc]initWithNibName:@"SettingViewController" bundle:nil] autorelease];


[self.navigationController pushViewController:settingViewController animated:YES];
}

Expand Down Expand Up @@ -157,7 +154,7 @@ - (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)
break;
default:
{
NSLog(@"unknown NSFetchedResultsChangeType");
DBLog(@"unknown NSFetchedResultsChangeType");
}
break;
}
Expand Down Expand Up @@ -223,13 +220,12 @@ - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEd

NSError* fetchingError;
if ([self.fetchResult performFetch:&fetchingError]){
NSLog(@"Successfully fetched.");
NSArray *rowsToDelete = [[NSArray alloc] initWithObjects:indexPath, nil] ;
[self.tableView deleteRowsAtIndexPaths:rowsToDelete withRowAnimation:UITableViewRowAnimationAutomatic];
[rowsToDelete release];
} else {
NSLog(@"Failed to fetch with error = %@", fetchingError);
}
DBLog(@"Failed to fetch with error = %@", fetchingError);
}
}

self.fetchResult.delegate = self;
Expand Down
Expand Up @@ -11,6 +11,7 @@
@interface SettingViewController : UIViewController
@property (retain, nonatomic) IBOutlet UIButton* cleanCD;
@property (retain, nonatomic) IBOutlet UISwitch* switchTypeGenerator;
@property (retain, nonatomic) IBOutlet UILabel* textSwitchLabel;
- (IBAction)cleanCoreData;
- (IBAction)engineSwitchTapped;

Expand Down
14 changes: 11 additions & 3 deletions RandomTimerApp/RandomTimerApp/Controllers/SettingViewController.m
Expand Up @@ -15,11 +15,12 @@ @interface SettingViewController ()
@implementation SettingViewController
@synthesize cleanCD;
@synthesize switchTypeGenerator;

@synthesize textSwitchLabel;
- (void)dealloc
{
self.cleanCD = nil;
self.switchTypeGenerator = nil;
self.textSwitchLabel = nil;
[super dealloc];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
Expand All @@ -35,6 +36,9 @@ - (void)viewDidLoad
{
[super viewDidLoad];
[self refreshFields];
//UI
self.textSwitchLabel.text = NSLocalizedString(@"Generate Number Local", @"");
self.cleanCD.titleLabel.text = NSLocalizedString(@"Clean CoreData", @"");

UIApplication *app = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillEnterForeground:) name:UIApplicationWillEnterForegroundNotification object:app];
Expand Down Expand Up @@ -73,17 +77,21 @@ - (void)cleanCoreData
}


- (void)applicationWillEnterForeground:(NSNotification *)notification { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults synchronize];
- (void)applicationWillEnterForeground:(NSNotification *)notification {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults synchronize];
[self refreshFields];
}

- (void)refreshFields {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
self.switchTypeGenerator.on = [defaults boolForKey:@"kRandom"];

}
- (IBAction)engineSwitchTapped {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSLog(@"--------%@",self.switchTypeGenerator.on?@"yes":@"no");
[defaults setBool:self.switchTypeGenerator.on forKey:@"kRandom"];
[defaults synchronize];
}
@end
@end

0 comments on commit 6d4117c

Please sign in to comment.