mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-12 22:40:25 +08:00
Audited all code in the app and produced extensive TODO list. Fixed build problems when on the Release profile.
This commit is contained in:
@@ -16,19 +16,23 @@
|
||||
if (self = [super initWithStyle:UITableViewStyleGrouped]) {
|
||||
_post = [[DBPost objectWithPrimaryKeyValue:postID] retain];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithTopicID:(NSString*)topicID {
|
||||
if (self = [super initWithStyle:UITableViewStyleGrouped]) {
|
||||
// TODO: Why are we using topic ID here?
|
||||
_topicID = [[NSNumber numberWithInt:[topicID intValue]] retain];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[_post release];
|
||||
[_topicID release];
|
||||
TT_RELEASE_SAFELY(_post);
|
||||
TT_RELEASE_SAFELY(_topicID);
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@@ -46,7 +50,10 @@
|
||||
self.tableViewStyle = UITableViewStyleGrouped;
|
||||
self.autoresizesForKeyboard = YES;
|
||||
self.variableHeightRows = YES;
|
||||
|
||||
[[TTNavigator navigator].URLMap from:@"db://updateAttachment" toObject:self selector:@selector(updateAttachment)];
|
||||
|
||||
// TODO: Use self.post method?
|
||||
if (nil == _post) {
|
||||
_post = [[DBPost object] retain];
|
||||
_post.topicID = _topicID;
|
||||
@@ -64,6 +71,7 @@
|
||||
}
|
||||
|
||||
- (void)createModel {
|
||||
// TODO: Move this into the model: [self.currentUser canModifyObject:_post]
|
||||
BOOL isAuthorizedUser = [[DBUser currentUser].userID isEqualToNumber:_post.userID] || [self isNewRecord];
|
||||
|
||||
NSMutableArray* items = [NSMutableArray array];
|
||||
@@ -75,6 +83,7 @@
|
||||
// has new attachment. show it. allow update.
|
||||
[items addObject:[TTTableImageItem itemWithText:@"Tap to Replace Image" imageURL:@"" defaultImage:_newAttachment URL:@"db://updateAttachment"]];
|
||||
} else if (![[_post attachmentPath] isWhitespaceAndNewlines]) {
|
||||
// TODO: Create model method to determine if there is an attachment
|
||||
// Has existing attachment. allow replace
|
||||
NSString* url = _post.attachmentPath;
|
||||
[items addObject:[TTTableImageItem itemWithText:@"Tap to Replace Image" imageURL:url defaultImage:nil URL:@"db://updateAttachment"]];
|
||||
@@ -115,15 +124,7 @@
|
||||
[self presentModalViewController:controller animated:YES];
|
||||
}
|
||||
|
||||
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
|
||||
_newAttachment = [info objectForKey:UIImagePickerControllerOriginalImage];
|
||||
[self dismissModalViewControllerAnimated:YES];
|
||||
[self invalidateModel];
|
||||
}
|
||||
|
||||
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
|
||||
[self dismissModalViewControllerAnimated:YES];
|
||||
}
|
||||
#pragma mark Actions
|
||||
|
||||
- (void)createButtonWasPressed:(id)sender {
|
||||
_post.body = _bodyTextEditor.text;
|
||||
@@ -131,7 +132,6 @@
|
||||
[[RKObjectManager sharedManager] postObject:_post delegate:self];
|
||||
}
|
||||
|
||||
|
||||
- (void)updateButtonWasPressed:(id)sender {
|
||||
_post.body = _bodyTextEditor.text;
|
||||
_post.newAttachment = _newAttachment;
|
||||
@@ -142,10 +142,26 @@
|
||||
[[RKObjectManager sharedManager] deleteObject:_post delegate:self];
|
||||
}
|
||||
|
||||
#pragma mark UIImagePickerControllerDelegate methods
|
||||
|
||||
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
|
||||
_newAttachment = [info objectForKey:UIImagePickerControllerOriginalImage];
|
||||
[self dismissModalViewControllerAnimated:YES];
|
||||
[self invalidateModel];
|
||||
}
|
||||
|
||||
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
|
||||
[self dismissModalViewControllerAnimated:YES];
|
||||
}
|
||||
|
||||
#pragma mark RKObjectLoaderDelegate methods
|
||||
|
||||
- (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects {
|
||||
// TODO: RKLog helpers?
|
||||
NSLog(@"Loaded Objects: %@", objects);
|
||||
NSLog(@"Status Code: %d", objectLoader.response.statusCode);
|
||||
// Post notification telling view controllers to reload.
|
||||
// TODO
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:kObjectCreatedUpdatedOrDestroyedNotificationName object:objects];
|
||||
// dismiss.
|
||||
[self.navigationController popViewControllerAnimated:YES];
|
||||
@@ -155,12 +171,15 @@
|
||||
[[[[UIAlertView alloc] initWithTitle:@"Error" message:[error localizedDescription] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease] show];
|
||||
}
|
||||
|
||||
// Text Editor Delegate
|
||||
#pragma mark TTTextEditorDelegate methods
|
||||
|
||||
- (void)textEditorDidBeginEditing:(TTTextEditor*)textEditor {
|
||||
UIBarButtonItem* doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:textEditor action:@selector(resignFirstResponder)];
|
||||
[doneButton autorelease];
|
||||
UIBarButtonItem* doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done"
|
||||
style:UIBarButtonItemStyleDone
|
||||
target:textEditor
|
||||
action:@selector(resignFirstResponder)];
|
||||
self.navigationItem.rightBarButtonItem = doneButton;
|
||||
[doneButton release];
|
||||
}
|
||||
|
||||
- (void)textEditorDidEndEditing:(TTTextEditor*)textEditor {
|
||||
|
||||
Reference in New Issue
Block a user