-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommentsViewController.m
103 lines (72 loc) · 2.59 KB
/
CommentsViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//
// CommentsViewController.m
// MemoryCapsule
//
// Created by Gonzalo Parajon on 4/23/13.
// Copyright (c) 2013 teambrown. All rights reserved.
//
#import "CommentsViewController.h"
@interface CommentsViewController (){
PFUser * user;
NSString * capsule, *imageID;
ImageDetailViewController * parentViewController;
}
@end
@implementation CommentsViewController
@synthesize commentTextView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil;
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
// Set username
user = [PFUser currentUser];
return self;
}
#pragma - mark UITextViewDelegate methods
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range
replacementText:(NSString *)text
{
NSLog(@"return ");
// Any new character added is passed in as the "text" parameter
if ([text isEqualToString:@"\n"]) {
// Be sure to test for equality using the "isEqualToString" message
[textView resignFirstResponder];
// Return FALSE so that the final '\n' character doesn't get added
return FALSE;
}
// For any other character return TRUE so that the text gets added to the view
return TRUE;
}
- (void)textViewDidEndEditing:(UITextView *)textView{
NSLog(@"ended editing %@", capsule);
// Save Comment
PFObject * newComment = [PFObject objectWithClassName:@"Comments"];
[newComment setObject:user.username forKey:@"by"];
[newComment setObject:capsule forKey:@"capsuleName"];
[newComment setObject:commentTextView.text forKey:@"comment"];
[newComment setObject: imageID forKey: @"imageID"];
[newComment save];
//[parentViewController.commentsArray addObject:newComment];
// NSLog(@"items: %i",[parentViewController.commentsArray count]);
[self performSelector:@selector(delayedReloadData) withObject:nil afterDelay:1.0];
}
-(void)delayedReloadData{
NSLog(@"delay reload data called");
//[commentsTable reloadData];
[self dismissViewControllerAnimated:YES completion:^{
[self.view removeFromSuperview];
}];
}
-(void) setCapsuleValues: (NSString *) capsuleName imageID: (NSString *) ID{
capsule = capsuleName;
imageID = ID;
}
-(void) linkToParentView: (ImageDetailViewController *) parent{
NSLog(@"LinkToParentTableView called");
parentViewController = parent;
parentViewController.title = @"test";
//NSLog(@"items: %i",[parentViewController.commentsArray count]);
}
@end