Created
February 6, 2012 19:40
-
-
Save EchoAbstract/1754317 to your computer and use it in GitHub Desktop.
iOS Demo for Blog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// If you have a userController that manages a view for logging-in/creating users | |
- (IBAction)loginUser:(id)sender | |
{ | |
// Log in the user and notify this class that logging-in completed | |
[KCSUser loginWithUsername:self.username.text password:self.username.password withDelegate:self]; | |
} | |
- (IBAction)createUser:(id)sender | |
{ | |
// Create the user and notify this class that creating completed | |
[KCSUser userWithUsername:self.username.text password:self.username.password withDelegate:self]; | |
} | |
- (void)user:(KCSUser *)user actionDidFailWithError:(NSError *)error | |
{ | |
// In this case we just notify the user, but normally you'd try to recover | |
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:[error localizedDescription] | |
message:[error localizedFailureReason] | |
delegate:self cancelButtonTitle:@"Ok" | |
otherButtonTitles:nil] autorelease]; | |
[alert show]; | |
} | |
- (void)user:(KCSUser *)user actionDidCompleteWithResult:(KCSUserActionResult)result | |
{ | |
// Log that we either created or logged in the user (if you care which, check result) | |
NSLog(@"Success for user: %@", user); | |
// Dismiss this controller, assuming that it's Modal | |
[self dismissModalViewControllerAnimated: YES]; | |
} | |
- (void)findNames | |
{ | |
// We pull this from a UITextView | |
NSString *nameToFind = self.userToFindTextView.text; | |
// Grab the current user | |
KCSUser *user = [[KCSClient sharedClient] currentUser]; | |
// Get an interface into the Users Collection | |
KCSCollection *users = [user userCollection]; | |
// Add a filter for names to find | |
[users addFilterCriteriaForProperty:@"name" | |
withStringValue:nameToFind | |
filteredByOperator:KCS_EQUALS_OPERATOR]; | |
// Make the request | |
[users fetchWithDelegate:self]; | |
} | |
- (void)collection:(KCSCollection *)collection didCompleteWithResult:(NSArray *)result | |
{ | |
// The request was complete, update your table | |
self.tableViewDataTable = result; | |
// Force the table to refresh its data | |
[self.tableView reloadData]; | |
} | |
- (void)collection:(KCSCollection *)collection didFailWithError:(NSError *)error | |
{ | |
// Something went wrong, just let the user know | |
// Typically you'd want to handle this condition | |
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:[error localizedDescription] | |
message:[error localizedFailureReason] | |
delegate:self cancelButtonTitle:@"Ok" | |
otherButtonTitles:nil] autorelease]; | |
[alert show]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment