Commits

Alfonso Alba García committed 8527c5d

Reloading data after saving person

Comments (0)

Files changed (7)

ParseTest.xcodeproj/project.pbxproj

 		AC88AD2216643895000D05F0 /* circle_plus.png in Resources */ = {isa = PBXBuildFile; fileRef = AC88AD2116643895000D05F0 /* circle_plus.png */; };
 		AC98FB67166E25A900912246 /* PTAddPersonViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = AC98FB65166E25A900912246 /* PTAddPersonViewController.m */; };
 		AC98FB6A166E2AE700912246 /* PTAddPersonViewController.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = AC98FB69166E2AE700912246 /* PTAddPersonViewController.storyboard */; };
+		AC98FB6C166E4EFB00912246 /* PersonTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = AC98FB6B166E4EFB00912246 /* PersonTableViewCell.xib */; };
 		ACBB31BF16657AB500078139 /* PTAddGroupViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = ACBB31BD16657AB500078139 /* PTAddGroupViewController.m */; };
 		ACBB31C016657AB500078139 /* PTAddGroupViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = ACBB31BE16657AB500078139 /* PTAddGroupViewController.xib */; };
 		ACBB31C316657EF800078139 /* wallpaper-568h@2x.jpg in Resources */ = {isa = PBXBuildFile; fileRef = ACBB31C216657EF800078139 /* wallpaper-568h@2x.jpg */; };
 		AC98FB64166E25A900912246 /* PTAddPersonViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PTAddPersonViewController.h; sourceTree = "<group>"; };
 		AC98FB65166E25A900912246 /* PTAddPersonViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PTAddPersonViewController.m; sourceTree = "<group>"; };
 		AC98FB69166E2AE700912246 /* PTAddPersonViewController.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = PTAddPersonViewController.storyboard; sourceTree = "<group>"; };
+		AC98FB6B166E4EFB00912246 /* PersonTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = PersonTableViewCell.xib; sourceTree = "<group>"; };
+		AC98FB6D166E552D00912246 /* PTPersonCRUDDelegateProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PTPersonCRUDDelegateProtocol.h; sourceTree = "<group>"; };
 		ACBB31BC16657AB500078139 /* PTAddGroupViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PTAddGroupViewController.h; sourceTree = "<group>"; };
 		ACBB31BD16657AB500078139 /* PTAddGroupViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PTAddGroupViewController.m; sourceTree = "<group>"; };
 		ACBB31BE16657AB500078139 /* PTAddGroupViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = PTAddGroupViewController.xib; sourceTree = "<group>"; };
 		ACBB31C41665808100078139 /* wallpaper@2x.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "wallpaper@2x.jpg"; sourceTree = "<group>"; };
 		ACBB31C51665808100078139 /* wallpaper.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = wallpaper.png; sourceTree = "<group>"; };
 		ACBB31CE16658DBB00078139 /* MainWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MainWindow.xib; sourceTree = "<group>"; };
-		ACC05AFD166A55F400C4624E /* PTGroupDataSourceProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PTGroupDataSourceProtocol.h; sourceTree = "<group>"; };
+		ACC05AFD166A55F400C4624E /* PTGroupCRUDDelegateProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PTGroupCRUDDelegateProtocol.h; sourceTree = "<group>"; };
 		ACC05AFF166A5CFC00C4624E /* Parse.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Parse.framework; sourceTree = "<group>"; };
 		ACC05B02166A5DAE00C4624E /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; };
 		ACC05B04166A5DFB00C4624E /* Accounts.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Accounts.framework; path = System/Library/Frameworks/Accounts.framework; sourceTree = SDKROOT; };
 				ACBB31BD16657AB500078139 /* PTAddGroupViewController.m */,
 				ACBB31BE16657AB500078139 /* PTAddGroupViewController.xib */,
 				AC88AD0D1663AF29000D05F0 /* StandardTableViewCell.xib */,
+				AC98FB6B166E4EFB00912246 /* PersonTableViewCell.xib */,
 				AC88ACFB1662AB8E000D05F0 /* PTPeopleViewController.h */,
 				AC88ACFC1662AB8E000D05F0 /* PTPeopleViewController.m */,
 				AC88ACFD1662AB8E000D05F0 /* PTPeopleViewController.xib */,
 				AC88AD1A1663F778000D05F0 /* PTGroupsNavController.h */,
 				AC88AD1B1663F778000D05F0 /* PTGroupsNavController.m */,
-				ACC05AFD166A55F400C4624E /* PTGroupDataSourceProtocol.h */,
+				ACC05AFD166A55F400C4624E /* PTGroupCRUDDelegateProtocol.h */,
 				AC98FB64166E25A900912246 /* PTAddPersonViewController.h */,
 				AC98FB65166E25A900912246 /* PTAddPersonViewController.m */,
 				AC98FB69166E2AE700912246 /* PTAddPersonViewController.storyboard */,
+				AC98FB6D166E552D00912246 /* PTPersonCRUDDelegateProtocol.h */,
 			);
 			path = ParseTest;
 			sourceTree = "<group>";
 				ACBB31C71665808100078139 /* wallpaper.png in Resources */,
 				ACBB31CF16658DBB00078139 /* MainWindow.xib in Resources */,
 				AC98FB6A166E2AE700912246 /* PTAddPersonViewController.storyboard in Resources */,
+				AC98FB6C166E4EFB00912246 /* PersonTableViewCell.xib in Resources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

ParseTest/PTAddPersonViewController.h

 //
 
 #import <UIKit/UIKit.h>
-
+#import "PTPersonCRUDDelegateProtocol.h"
 @interface PTAddPersonViewController : UITableViewController <UITextFieldDelegate>
 
 @property (weak, nonatomic) IBOutlet UITextField *firstNameTextField;
 @property (weak, nonatomic) IBOutlet UITextField *emailTextField;
 @property (weak, nonatomic) IBOutlet UITextField *twitterTextField;
 
+@property (strong, nonatomic) id<PTPersonCRUDDelegateProtocol> delegate;
+
 @end

ParseTest/PTAddPersonViewController.m

 }
 
 
+
 #pragma mark Actions
 - (void) savePersonAction:(id)sender
 {
     NSLog(@"Saving person");
-    PFObject *person = [PFObject objectWithClassName:@"Person"];
-    [person setObject:self.firstNameTextField.text forKey:@"firstName"];
-    [person setObject:self.lastNameTextField.text forKey:@"lastName"];
-    [person setObject:self.emailTextField.text forKey:@"email"];
-    [person setObject:self.twitterTextField.text forKey:@"twitter"];
-    [person saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
-        if(succeeded)
-        {
-            dispatch_async(dispatch_get_main_queue(),^{
-                [self.navigationController popViewControllerAnimated:YES];
-            });
-        }
-        else
-        {
-            NSLog(@"Person could not be saved.");
-        }
-    }];
+    NSArray *objects = [NSArray arrayWithObjects:self.firstNameTextField.text, self.lastNameTextField.text, self.emailTextField.text, self.twitterTextField.text, nil];
+    NSArray *keys = [NSArray arrayWithObjects:@"firstName",@"lastName",@"email",@"twitter", nil];
+    NSDictionary *data = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
+    [self.delegate addPerson:data];
+    [self.navigationController popViewControllerAnimated:YES];
 }
 
 - (void) dismissKeyboard

ParseTest/PTPeopleViewController.h

 //
 
 #import <UIKit/UIKit.h>
-
-@interface PTPeopleViewController : UITableViewController <UITableViewDataSource, UITableViewDelegate>
+#import "PTPersonCRUDDelegateProtocol.h"
+@interface PTPeopleViewController : UITableViewController <PTPersonCRUDDelegateProtocol>
 
 @end

ParseTest/PTPeopleViewController.m

 //
 
 #import "PTPeopleViewController.h"
+#import "PTAddPersonViewController.h"
+#import <Parse/Parse.h>
 
 @interface PTPeopleViewController ()
-
+{
+    NSArray *people;
+}
 @end
 
 @implementation PTPeopleViewController
     self.title = @"People";
     UIBarButtonItem *addPersonButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addPersonAction:)];
     self.navigationItem.rightBarButtonItem = addPersonButton;
+    [self.tableView registerNib:[UINib nibWithNibName:@"PersonTableViewCell" bundle:nil] forCellReuseIdentifier:@"PersonCell"];
+    [self loadDataInBackground];
 }
 
 - (void)viewDidLoad
     // Dispose of any resources that can be recreated.
 }
 
+#pragma mark UITableViewDataSource
+
+- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
+{
+    return [people count];
+}
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PersonCell" forIndexPath:indexPath];
+    PFObject *person = [people objectAtIndex:indexPath.row];
+    NSString *name = [[person objectForKey:@"firstName" ] stringByAppendingString:@" "];
+    name = [name stringByAppendingString:[person objectForKey:@"lastName"]];
+    cell.textLabel.text = name;
+    cell.detailTextLabel.text = @"GROUP";
+    return cell;
+}
+
+#pragma mark Parse Related Functions
+
+- (void) loadDataInBackground
+{
+    PFQuery *query = [PFQuery queryWithClassName:@"Person"];
+    [query orderByAscending:@"firstName"];
+    [query orderByAscending:@"lastName"];
+    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
+        if(!error)
+        {
+            people = objects;
+            dispatch_async(dispatch_get_main_queue(), ^{
+                [self.tableView reloadData];
+            });
+        }
+    }];
+}
+
+#pragma mark Actions
+
 - (void) addPersonAction:(id) sender
 {
     NSLog(@"Add person pressed");
     UIStoryboard *tableViewStoryboard = [UIStoryboard storyboardWithName:@"PTAddPersonViewController" bundle:nil];
-    PTPeopleViewController *viewController = [tableViewStoryboard instantiateViewControllerWithIdentifier:@"PTAddPersonViewController"];
+    PTAddPersonViewController *viewController = [tableViewStoryboard instantiateViewControllerWithIdentifier:@"PTAddPersonViewController"];
+    viewController.delegate = self;
     [self.navigationController pushViewController:viewController animated:YES];
 }
+
+#pragma mark PTPersonCRUDDelegateProtocol
+
+- (void) addPerson:(NSDictionary *)data
+{
+    PFObject *person = [PFObject objectWithClassName:@"Person"];
+    [person setObject:[data objectForKey:@"firstName"] forKey:@"firstName"];
+    [person setObject:[data objectForKey:@"lastName"] forKey:@"lastName"];
+    [person setObject:[data objectForKey:@"email"] forKey:@"email"];
+    [person setObject:[data objectForKey:@"twitter"] forKey:@"twitter"];
+    
+    [person saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
+        if(succeeded)
+        {
+            dispatch_async(dispatch_get_main_queue(), ^{
+                [self loadDataInBackground];
+            });
+        }
+        else
+        {
+            NSLog(@"Person could not be saved.");
+        }
+    }];
+    
+}
 @end

ParseTest/PTPersonCRUDDelegateProtocol.h

 
 @protocol PTPersonCRUDDelegateProtocol <NSObject>
 
+@required
+- (void) addPerson:(NSDictionary *)data;
+
+
 @end

ParseTest/PersonTableViewCell.xib

 <archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="8.00">
 	<data>
 		<int key="IBDocument.SystemTarget">1536</int>
-		<string key="IBDocument.SystemVersion">12A206j</string>
-		<string key="IBDocument.InterfaceBuilderVersion">2519</string>
-		<string key="IBDocument.AppKitVersion">1172.1</string>
-		<string key="IBDocument.HIToolboxVersion">613.00</string>
+		<string key="IBDocument.SystemVersion">12C60</string>
+		<string key="IBDocument.InterfaceBuilderVersion">2844</string>
+		<string key="IBDocument.AppKitVersion">1187.34</string>
+		<string key="IBDocument.HIToolboxVersion">625.00</string>
 		<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
 			<string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
-			<string key="NS.object.0">1856</string>
+			<string key="NS.object.0">1930</string>
 		</object>
 		<array key="IBDocument.IntegratedClassDependencies">
 			<string>IBProxyObject</string>
+			<string>IBUILabel</string>
+			<string>IBUITableViewCell</string>
 		</array>
 		<array key="IBDocument.PluginDependencies">
 			<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
 				<string key="IBProxiedObjectIdentifier">IBFirstResponder</string>
 				<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
 			</object>
+			<object class="IBUITableViewCell" id="498885987">
+				<reference key="NSNextResponder"/>
+				<int key="NSvFlags">292</int>
+				<array class="NSMutableArray" key="NSSubviews">
+					<object class="IBUIView" id="35939239">
+						<reference key="NSNextResponder" ref="498885987"/>
+						<int key="NSvFlags">256</int>
+						<array class="NSMutableArray" key="NSSubviews">
+							<object class="IBUILabel" id="272883728">
+								<reference key="NSNextResponder" ref="35939239"/>
+								<int key="NSvFlags">256</int>
+								<string key="NSFrame">{{10, 2}, {38, 22}}</string>
+								<reference key="NSSuperview" ref="35939239"/>
+								<bool key="IBUIOpaque">NO</bool>
+								<bool key="IBUIClipsSubviews">YES</bool>
+								<int key="IBUIContentMode">7</int>
+								<bool key="IBUIMultipleTouchEnabled">YES</bool>
+								<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+								<string key="IBUIText">Title</string>
+								<object class="NSColor" key="IBUITextColor">
+									<int key="NSColorSpace">1</int>
+									<bytes key="NSRGB">MCAwIDAAA</bytes>
+									<string key="IBUIColorCocoaTouchKeyPath">darkTextColor</string>
+								</object>
+								<object class="NSColor" key="IBUIHighlightedColor" id="609935103">
+									<int key="NSColorSpace">1</int>
+									<bytes key="NSRGB">MSAxIDEAA</bytes>
+								</object>
+								<int key="IBUIBaselineAdjustment">0</int>
+								<object class="IBUIFontDescription" key="IBUIFontDescription">
+									<int key="type">2</int>
+									<double key="pointSize">18</double>
+								</object>
+								<object class="NSFont" key="IBUIFont">
+									<string key="NSName">Helvetica-Bold</string>
+									<double key="NSSize">18</double>
+									<int key="NSfFlags">16</int>
+								</object>
+								<bool key="IBUIAdjustsFontSizeToFit">NO</bool>
+							</object>
+							<object class="IBUILabel" id="493393242">
+								<reference key="NSNextResponder" ref="35939239"/>
+								<int key="NSvFlags">256</int>
+								<string key="NSFrame">{{10, 24}, {36, 18}}</string>
+								<reference key="NSSuperview" ref="35939239"/>
+								<bool key="IBUIOpaque">NO</bool>
+								<bool key="IBUIClipsSubviews">YES</bool>
+								<int key="IBUIContentMode">7</int>
+								<bool key="IBUIMultipleTouchEnabled">YES</bool>
+								<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+								<string key="IBUIText">Detail</string>
+								<object class="NSColor" key="IBUITextColor">
+									<int key="NSColorSpace">1</int>
+									<bytes key="NSRGB">MC41MDE5NjA3ODQzIDAuNTAxOTYwNzg0MyAwLjUwMTk2MDc4NDMAA</bytes>
+								</object>
+								<reference key="IBUIHighlightedColor" ref="609935103"/>
+								<int key="IBUIBaselineAdjustment">0</int>
+								<object class="IBUIFontDescription" key="IBUIFontDescription">
+									<int key="type">1</int>
+									<double key="pointSize">14</double>
+								</object>
+								<object class="NSFont" key="IBUIFont">
+									<string key="NSName">Helvetica</string>
+									<double key="NSSize">14</double>
+									<int key="NSfFlags">16</int>
+								</object>
+								<bool key="IBUIAdjustsFontSizeToFit">NO</bool>
+							</object>
+						</array>
+						<string key="NSFrameSize">{300, 43}</string>
+						<reference key="NSSuperview" ref="498885987"/>
+						<string key="NSReuseIdentifierKey">_NS:11</string>
+						<object class="NSColor" key="IBUIBackgroundColor">
+							<int key="NSColorSpace">3</int>
+							<bytes key="NSWhite">MCAwAA</bytes>
+						</object>
+						<bool key="IBUIOpaque">NO</bool>
+						<bool key="IBUIClipsSubviews">YES</bool>
+						<int key="IBUIContentMode">4</int>
+						<bool key="IBUIMultipleTouchEnabled">YES</bool>
+						<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+					</object>
+				</array>
+				<string key="NSFrameSize">{320, 44}</string>
+				<reference key="NSSuperview"/>
+				<reference key="NSNextKeyView" ref="35939239"/>
+				<string key="NSReuseIdentifierKey">_NS:9</string>
+				<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+				<int key="IBUIAccessoryType">1</int>
+				<reference key="IBUIContentView" ref="35939239"/>
+				<string key="IBUIReuseIdentifier">PersonCell</string>
+				<real value="3" key="IBUIStyle"/>
+				<reference key="IBUITextLabel" ref="272883728"/>
+				<reference key="IBUIDetailTextLabel" ref="493393242"/>
+			</object>
 		</array>
 		<object class="IBObjectContainer" key="IBDocument.Objects">
 			<array class="NSMutableArray" key="connectionRecords"/>
 						<reference key="object" ref="371349661"/>
 						<reference key="parent" ref="0"/>
 					</object>
+					<object class="IBObjectRecord">
+						<int key="objectID">2</int>
+						<reference key="object" ref="498885987"/>
+						<array class="NSMutableArray" key="children">
+							<reference ref="272883728"/>
+							<reference ref="493393242"/>
+						</array>
+						<reference key="parent" ref="0"/>
+					</object>
+					<object class="IBObjectRecord">
+						<int key="objectID">3</int>
+						<reference key="object" ref="272883728"/>
+						<reference key="parent" ref="498885987"/>
+					</object>
+					<object class="IBObjectRecord">
+						<int key="objectID">4</int>
+						<reference key="object" ref="493393242"/>
+						<reference key="parent" ref="498885987"/>
+					</object>
 				</array>
 			</object>
 			<dictionary class="NSMutableDictionary" key="flattenedProperties">
 				<string key="-1.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
 				<string key="-2.CustomClassName">UIResponder</string>
 				<string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+				<string key="2.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+				<string key="3.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+				<boolean value="NO" key="3.IBViewMetadataTranslatesAutoresizingMaskIntoConstraints"/>
+				<string key="4.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+				<boolean value="NO" key="4.IBViewMetadataTranslatesAutoresizingMaskIntoConstraints"/>
 			</dictionary>
 			<dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>
 			<nil key="activeLocalization"/>
 			<dictionary class="NSMutableDictionary" key="localizations"/>
 			<nil key="sourceID"/>
-			<int key="maxID">1</int>
+			<int key="maxID">4</int>
 		</object>
 		<object class="IBClassDescriber" key="IBDocument.Classes"/>
 		<int key="IBDocument.localizationMode">0</int>
 		<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
 		<int key="IBDocument.defaultPropertyAccessControl">3</int>
 		<bool key="IBDocument.UseAutolayout">YES</bool>
-		<string key="IBCocoaTouchPluginVersion">1856</string>
+		<string key="IBCocoaTouchPluginVersion">1930</string>
 	</data>
 </archive>