-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTSAddNewTableViewCell.m
More file actions
93 lines (75 loc) · 2.62 KB
/
Copy pathTSAddNewTableViewCell.m
File metadata and controls
93 lines (75 loc) · 2.62 KB
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
//
// TSAddNewTableViewCell.m
// TimeStamp-Homepage
//
// Created by Awais Hussain on 8/17/13.
// Copyright (c) 2013 Awais Hussain. All rights reserved.
//
#import "TSAddNewTableViewCell.h"
@implementation TSAddNewTableViewCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
self.textLabel.hidden = YES;
self.textField = [[UITextField alloc] init];
self.textField.textColor = [UIColor whiteColor];
self.textField.font = self.textLabel.font;
// I don't think setting the font here does anything. textLabel has not yet been configured.
// self.textField.placeholder = @"Add New";
self.textField.textAlignment = NSTextAlignmentCenter;
self.textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
self.textField.delegate = self;
[self addSubview:self.textField];
UIImage *image = [UIImage imageNamed:@"plus_sign"];
imageView = [[UIImageView alloc] initWithImage:image];
imageView.alpha = 0.8;
[self addSubview:imageView];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dismissKeyboard) name:@"hideKeyboard" object:nil];
}
return self;
}
- (void)drawPlusSign {
}
- (void)layoutSubviews {
[super layoutSubviews];
self.textField.center = self.center;
self.textField.bounds = self.bounds;
imageView.center = self.center;
imageView.bounds = CGRectMake(0,0,40,40);
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (void)dismissKeyboard {
userCancelledTextEntry = YES;
imageView.hidden = NO;
[self.textField resignFirstResponder];
}
#pragma mark UITextViewDelegate methods
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if (textField == self.textField) {
userCancelledTextEntry = NO;
imageView.hidden = YES;
}
return YES;
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[self.textField resignFirstResponder];
return YES;
}
- (void)textFieldDidEndEditing:(UITextField *)textField {
if (userCancelledTextEntry || [self.textField.text length] == 0) {
// Do nothing, cancelled or failed validation tests.
self.textField.text = @"";
} else {
// Save the new subcategory
[self.addDelegate addNewSubcategoryWithString:self.textField.text];
}
}
@end