Commits

Alfonso Alba García committed 3644782

Save Person Form

  • Participants
  • Parent commits 5f1acc6

Comments (0)

Files changed (6)

File ParseTest.xcodeproj/project.pbxproj

 		AC88AD0E1663AF29000D05F0 /* StandardTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = AC88AD0D1663AF29000D05F0 /* StandardTableViewCell.xib */; };
 		AC88AD1C1663F778000D05F0 /* PTGroupsNavController.m in Sources */ = {isa = PBXBuildFile; fileRef = AC88AD1B1663F778000D05F0 /* PTGroupsNavController.m */; };
 		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 */; };
 		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 */; };
 		AC88AD1A1663F778000D05F0 /* PTGroupsNavController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PTGroupsNavController.h; sourceTree = "<group>"; };
 		AC88AD1B1663F778000D05F0 /* PTGroupsNavController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PTGroupsNavController.m; sourceTree = "<group>"; };
 		AC88AD2116643895000D05F0 /* circle_plus.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = circle_plus.png; sourceTree = "<group>"; };
+		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>"; };
 		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>"; };
 				AC88AD1A1663F778000D05F0 /* PTGroupsNavController.h */,
 				AC88AD1B1663F778000D05F0 /* PTGroupsNavController.m */,
 				ACC05AFD166A55F400C4624E /* PTGroupDataSourceProtocol.h */,
+				AC98FB64166E25A900912246 /* PTAddPersonViewController.h */,
+				AC98FB65166E25A900912246 /* PTAddPersonViewController.m */,
+				AC98FB69166E2AE700912246 /* PTAddPersonViewController.storyboard */,
 			);
 			path = ParseTest;
 			sourceTree = "<group>";
 				ACBB31C61665808100078139 /* wallpaper@2x.jpg in Resources */,
 				ACBB31C71665808100078139 /* wallpaper.png in Resources */,
 				ACBB31CF16658DBB00078139 /* MainWindow.xib in Resources */,
+				AC98FB6A166E2AE700912246 /* PTAddPersonViewController.storyboard in Resources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
 				AC88ACFE1662AB8E000D05F0 /* PTPeopleViewController.m in Sources */,
 				AC88AD1C1663F778000D05F0 /* PTGroupsNavController.m in Sources */,
 				ACBB31BF16657AB500078139 /* PTAddGroupViewController.m in Sources */,
+				AC98FB67166E25A900912246 /* PTAddPersonViewController.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

File ParseTest/PTAddGroupViewController.m

     return YES;
 }
 
+#pragma mark Actions
 - (IBAction)saveGroup:(UIButton *)sender {
     [self.delegate addGroup:self.textField.text];
     [self.textField resignFirstResponder];

File ParseTest/PTAddPersonViewController.h

+//
+//  PTAddPersonViewController.h
+//  ParseTest
+//
+//  Created by Alfonso Alba on 04/12/12.
+//  Copyright (c) 2012 Alfonso Alba. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface PTAddPersonViewController : UITableViewController <UITextFieldDelegate>
+
+@property (weak, nonatomic) IBOutlet UITextField *firstNameTextField;
+@property (weak, nonatomic) IBOutlet UITextField *lastNameTextField;
+@property (weak, nonatomic) IBOutlet UITextField *emailTextField;
+@property (weak, nonatomic) IBOutlet UITextField *twitterTextField;
+
+@end

File ParseTest/PTAddPersonViewController.m

+//
+//  PTAddPersonViewController.m
+//  ParseTest
+//
+//  Created by Alfonso Alba on 04/12/12.
+//  Copyright (c) 2012 Alfonso Alba. All rights reserved.
+//
+
+#import "PTAddPersonViewController.h"
+#import <Parse/Parse.h>
+@interface PTAddPersonViewController ()
+
+@end
+
+@implementation PTAddPersonViewController
+
+- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
+{
+    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
+    if (self) {
+        // Custom initialization
+    }
+    return self;
+}
+
+- (void)viewDidLoad
+{
+    [super viewDidLoad];
+    // Do any additional setup after loading the view from its nib.
+    UIBarButtonItem *done = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(savePersonAction:)];
+    self.navigationItem.rightBarButtonItem = done;
+    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
+                                   initWithTarget:self
+                                   action:@selector(dismissKeyboard)];
+    
+    [self.view addGestureRecognizer:tap];
+}
+
+- (void)didReceiveMemoryWarning
+{
+    [super didReceiveMemoryWarning];
+    // Dispose of any resources that can be recreated.
+}
+
+#pragma mark UITextFieldDelegate
+
+-(BOOL) textFieldShouldReturn:(UITextField *)textField
+{
+    [textField resignFirstResponder];
+    NSLog(@"In textFieldShouldReturn");
+    return YES;
+}
+
+
+#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.");
+        }
+    }];
+}
+
+- (void) dismissKeyboard
+{
+    [self.firstNameTextField resignFirstResponder];
+    [self.lastNameTextField resignFirstResponder];
+    [self.emailTextField resignFirstResponder];
+    [self.twitterTextField resignFirstResponder];
+}
+@end

File ParseTest/PTAddPersonViewController.storyboard

+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="2.0" toolsVersion="2844" systemVersion="12C60" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="IRh-Rw-SjJ">
+    <dependencies>
+        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="1930"/>
+    </dependencies>
+    <scenes>
+        <!--Add Person View Controller-->
+        <scene sceneID="er3-Lz-zgV">
+            <objects>
+                <tableViewController storyboardIdentifier="PTAddPersonViewController" id="IRh-Rw-SjJ" customClass="PTAddPersonViewController" sceneMemberID="viewController">
+                    <tableView key="view" opaque="NO" clipsSubviews="YES" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="static" style="grouped" separatorStyle="singleLineEtched" rowHeight="44" sectionHeaderHeight="10" sectionFooterHeight="10" id="XfO-Or-Mf7">
+                        <rect key="frame" x="0.0" y="20" width="320" height="548"/>
+                        <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
+                        <color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
+                        <sections>
+                            <tableViewSection headerTitle="Personal data" id="Hll-4g-9dC">
+                                <cells>
+                                    <tableViewCell contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" id="41x-SU-mj8">
+                                        <rect key="frame" x="0.0" y="46" width="320" height="45"/>
+                                        <autoresizingMask key="autoresizingMask"/>
+                                        <view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
+                                            <rect key="frame" x="10" y="1" width="300" height="43"/>
+                                            <autoresizingMask key="autoresizingMask"/>
+                                            <subviews>
+                                                <textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Name" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="WFW-CA-cbv">
+                                                    <constraints>
+                                                        <constraint firstAttribute="height" constant="30" id="cFX-sE-Oxi"/>
+                                                        <constraint firstAttribute="width" constant="260" id="fQZ-3w-6F4"/>
+                                                    </constraints>
+                                                    <fontDescription key="fontDescription" type="system" pointSize="14"/>
+                                                    <textInputTraits key="textInputTraits"/>
+                                                    <connections>
+                                                        <outlet property="delegate" destination="IRh-Rw-SjJ" id="3RQ-yx-FK6"/>
+                                                    </connections>
+                                                </textField>
+                                            </subviews>
+                                            <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
+                                        </view>
+                                        <constraints>
+                                            <constraint firstItem="WFW-CA-cbv" firstAttribute="centerX" secondItem="41x-SU-mj8" secondAttribute="centerX" type="default" id="nDM-Xw-i7F"/>
+                                            <constraint firstItem="WFW-CA-cbv" firstAttribute="centerY" secondItem="41x-SU-mj8" secondAttribute="centerY" type="default" id="ooY-pR-xxo"/>
+                                        </constraints>
+                                    </tableViewCell>
+                                    <tableViewCell contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" id="BBF-Dq-T3p">
+                                        <rect key="frame" x="0.0" y="91" width="320" height="45"/>
+                                        <autoresizingMask key="autoresizingMask"/>
+                                        <view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
+                                            <rect key="frame" x="10" y="0.0" width="300" height="43"/>
+                                            <autoresizingMask key="autoresizingMask"/>
+                                            <subviews>
+                                                <textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Surname" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="jkX-Qf-qHC">
+                                                    <constraints>
+                                                        <constraint firstAttribute="height" constant="30" id="GfO-Vj-Q4O"/>
+                                                        <constraint firstAttribute="width" constant="260" id="IB0-lR-TW4"/>
+                                                    </constraints>
+                                                    <fontDescription key="fontDescription" type="system" pointSize="14"/>
+                                                    <textInputTraits key="textInputTraits"/>
+                                                    <connections>
+                                                        <outlet property="delegate" destination="IRh-Rw-SjJ" id="L6K-KD-fAu"/>
+                                                    </connections>
+                                                </textField>
+                                            </subviews>
+                                            <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
+                                        </view>
+                                        <constraints>
+                                            <constraint firstItem="jkX-Qf-qHC" firstAttribute="centerY" secondItem="BBF-Dq-T3p" secondAttribute="centerY" type="default" id="99D-ao-v7L"/>
+                                            <constraint firstItem="jkX-Qf-qHC" firstAttribute="centerX" secondItem="BBF-Dq-T3p" secondAttribute="centerX" type="default" id="ieU-Nl-BoU"/>
+                                        </constraints>
+                                    </tableViewCell>
+                                </cells>
+                            </tableViewSection>
+                            <tableViewSection headerTitle="Contact Info" id="P99-nr-Lal">
+                                <cells>
+                                    <tableViewCell contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" id="0OB-hS-6RW">
+                                        <rect key="frame" x="0.0" y="182" width="320" height="45"/>
+                                        <autoresizingMask key="autoresizingMask"/>
+                                        <view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
+                                            <rect key="frame" x="10" y="1" width="300" height="43"/>
+                                            <autoresizingMask key="autoresizingMask"/>
+                                            <subviews>
+                                                <textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="email" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="qIi-jj-IHo">
+                                                    <constraints>
+                                                        <constraint firstAttribute="width" constant="260" id="KH7-ZM-bQY"/>
+                                                        <constraint firstAttribute="height" constant="30" id="TWE-Ke-jrh"/>
+                                                    </constraints>
+                                                    <fontDescription key="fontDescription" type="system" pointSize="14"/>
+                                                    <textInputTraits key="textInputTraits"/>
+                                                    <connections>
+                                                        <outlet property="delegate" destination="IRh-Rw-SjJ" id="037-EB-coK"/>
+                                                    </connections>
+                                                </textField>
+                                            </subviews>
+                                            <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
+                                        </view>
+                                        <constraints>
+                                            <constraint firstItem="qIi-jj-IHo" firstAttribute="centerX" secondItem="0OB-hS-6RW" secondAttribute="centerX" type="default" id="39A-jf-mCd"/>
+                                            <constraint firstItem="qIi-jj-IHo" firstAttribute="top" secondItem="0OB-hS-6RW" secondAttribute="top" constant="8" id="LYV-qR-oAh"/>
+                                        </constraints>
+                                    </tableViewCell>
+                                    <tableViewCell contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" id="kw6-ff-05h">
+                                        <rect key="frame" x="0.0" y="227" width="320" height="45"/>
+                                        <autoresizingMask key="autoresizingMask"/>
+                                        <view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
+                                            <rect key="frame" x="10" y="0.0" width="300" height="43"/>
+                                            <autoresizingMask key="autoresizingMask"/>
+                                            <subviews>
+                                                <textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="twitter" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="wcG-iT-iaz">
+                                                    <constraints>
+                                                        <constraint firstAttribute="height" constant="30" id="0Hi-EN-0z6"/>
+                                                        <constraint firstAttribute="width" constant="260" id="yoT-xq-fm0"/>
+                                                    </constraints>
+                                                    <fontDescription key="fontDescription" type="system" pointSize="14"/>
+                                                    <textInputTraits key="textInputTraits"/>
+                                                    <connections>
+                                                        <outlet property="delegate" destination="IRh-Rw-SjJ" id="SmH-Ve-u0y"/>
+                                                    </connections>
+                                                </textField>
+                                            </subviews>
+                                            <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
+                                        </view>
+                                        <constraints>
+                                            <constraint firstItem="wcG-iT-iaz" firstAttribute="centerY" secondItem="kw6-ff-05h" secondAttribute="centerY" type="default" id="DKC-VI-abF"/>
+                                            <constraint firstItem="wcG-iT-iaz" firstAttribute="centerX" secondItem="kw6-ff-05h" secondAttribute="centerX" type="default" id="WHb-JF-40P"/>
+                                        </constraints>
+                                    </tableViewCell>
+                                </cells>
+                            </tableViewSection>
+                        </sections>
+                        <connections>
+                            <outlet property="dataSource" destination="IRh-Rw-SjJ" id="ypb-eX-ktB"/>
+                            <outlet property="delegate" destination="IRh-Rw-SjJ" id="oLe-7q-mq1"/>
+                        </connections>
+                    </tableView>
+                    <connections>
+                        <outlet property="emailTextField" destination="qIi-jj-IHo" id="3Dy-3l-hqw"/>
+                        <outlet property="firstNameTextField" destination="WFW-CA-cbv" id="GP8-pa-TwG"/>
+                        <outlet property="lastNameTextField" destination="jkX-Qf-qHC" id="kSe-1E-4ut"/>
+                        <outlet property="twitterTextField" destination="wcG-iT-iaz" id="Zub-f4-cML"/>
+                    </connections>
+                </tableViewController>
+                <placeholder placeholderIdentifier="IBFirstResponder" id="leH-Gv-mBE" userLabel="First Responder" sceneMemberID="firstResponder"/>
+            </objects>
+            <point key="canvasLocation" x="327" y="17"/>
+        </scene>
+    </scenes>
+    <classes>
+        <class className="NSLayoutConstraint" superclassName="NSObject">
+            <source key="sourceIdentifier" type="project" relativePath="./Classes/NSLayoutConstraint.h"/>
+        </class>
+        <class className="PTAddPersonViewController" superclassName="UITableViewController">
+            <source key="sourceIdentifier" type="project" relativePath="./Classes/PTAddPersonViewController.h"/>
+            <relationships>
+                <relationship kind="outlet" name="emailTextField" candidateClass="UITextField"/>
+                <relationship kind="outlet" name="firstNameTextField" candidateClass="UITextField"/>
+                <relationship kind="outlet" name="lastNameTextField" candidateClass="UITextField"/>
+                <relationship kind="outlet" name="twitterTextField" candidateClass="UITextField"/>
+            </relationships>
+        </class>
+    </classes>
+    <simulatedMetricsContainer key="defaultSimulatedMetrics">
+        <simulatedStatusBarMetrics key="statusBar"/>
+        <simulatedOrientationMetrics key="orientation"/>
+        <simulatedScreenMetrics key="destination" type="retina4"/>
+    </simulatedMetricsContainer>
+</document>

File ParseTest/PTPeopleViewController.m

 - (void) addPersonAction:(id) sender
 {
     NSLog(@"Add person pressed");
+    UIStoryboard *tableViewStoryboard = [UIStoryboard storyboardWithName:@"PTAddPersonViewController" bundle:nil];
+    PTPeopleViewController *viewController = [tableViewStoryboard instantiateViewControllerWithIdentifier:@"PTAddPersonViewController"];
+    [self.navigationController pushViewController:viewController animated:YES];
 }
 @end