PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/Classes/UVNewSuggestionViewController.m

https://github.com/appsocial/uservoice-iphone-sdk
Objective C | 618 lines | 493 code | 96 blank | 29 comment | 37 complexity | e018a22e2d178ccfbbbbc591a48e90b6 MD5 | raw file
  1. //
  2. // UVNewSuggestionViewController.m
  3. // UserVoice
  4. //
  5. // Created by UserVoice on 11/17/09.
  6. // Copyright 2009 UserVoice Inc. All rights reserved.
  7. //
  8. #import <QuartzCore/QuartzCore.h>
  9. #import "UVNewSuggestionViewController.h"
  10. #import "UVStyleSheet.h"
  11. #import "UVSuggestion.h"
  12. #import "UVForum.h"
  13. #import "UVCategory.h"
  14. #import "UVSession.h"
  15. #import "UVUser.h"
  16. #import "UVClientConfig.h"
  17. #import "UVSubdomain.h"
  18. #import "UVToken.h"
  19. #import "UVCategorySelectViewController.h"
  20. #import "UVNewTicketViewController.h"
  21. #import "UVSignInViewController.h"
  22. #import "UVTextEditor.h"
  23. #import "NSError+UVExtras.h"
  24. #define UV_NEW_SUGGESTION_SECTION_PROFILE 0
  25. #define UV_NEW_SUGGESTION_SECTION_TITLE 1
  26. #define UV_NEW_SUGGESTION_SECTION_TEXT 2
  27. #define UV_NEW_SUGGESTION_SECTION_CATEGORY 3
  28. #define UV_NEW_SUGGESTION_SECTION_VOTE 4
  29. #define UV_NEW_SUGGESTION_SECTION_SUBMIT 5
  30. @implementation UVNewSuggestionViewController
  31. @synthesize forum;
  32. @synthesize title;
  33. @synthesize text;
  34. @synthesize name;
  35. @synthesize email;
  36. @synthesize textEditor;
  37. @synthesize titleField;
  38. @synthesize nameField;
  39. @synthesize emailField;
  40. @synthesize prevLeftBarButton;
  41. @synthesize numVotes;
  42. @synthesize category;
  43. @synthesize shouldShowCategories;
  44. - (id)initWithForum:(UVForum *)theForum title:(NSString *)theTitle {
  45. if (self = [super init]) {
  46. self.forum = theForum;
  47. self.title = theTitle;
  48. self.shouldShowCategories = self.forum.availableCategories && [self.forum.availableCategories count] > 0;
  49. }
  50. return self;
  51. }
  52. - (void)didReceiveError:(NSError *)error {
  53. NSLog(@"Got error: %@", [error userInfo]);
  54. if ([error isNotFoundError]) {
  55. [self hideActivityIndicator];
  56. NSLog(@"No user");
  57. } else if ([error isUVRecordInvalidForField:@"title" withMessage:@"is not allowed."]) {
  58. [self hideActivityIndicator];
  59. [[[[UIAlertView alloc]
  60. initWithTitle:@"Error"
  61. message:@"A suggestion with this title already exists. Please change the title."
  62. delegate:nil
  63. cancelButtonTitle:@"OK"
  64. otherButtonTitles:nil] autorelease]
  65. show];
  66. }
  67. else
  68. {
  69. [super didReceiveError:error];
  70. }
  71. }
  72. - (void)createSuggestion {
  73. [self showActivityIndicator];
  74. [UVSuggestion createWithForum:self.forum
  75. category:self.category
  76. title:self.title
  77. text:self.text
  78. votes:self.numVotes
  79. delegate:self];
  80. }
  81. - (void)dismissKeyboard {
  82. shouldResizeForKeyboard = YES;
  83. [nameField resignFirstResponder];
  84. [emailField resignFirstResponder];
  85. [textEditor resignFirstResponder];
  86. }
  87. - (void)updateFromTextFields {
  88. self.title = titleField.text;
  89. self.name = nameField.text;
  90. self.email = emailField.text;
  91. [self dismissKeyboard];
  92. }
  93. - (void)createButtonTapped {
  94. [self updateFromTextFields];
  95. if ([UVSession currentSession].user) {
  96. [self createSuggestion];
  97. } else {
  98. if (self.email && [self.email length] > 1) {
  99. [self showActivityIndicator];
  100. [UVUser findOrCreateWithEmail:self.email andName:self.name andDelegate:self];
  101. } else {
  102. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
  103. message:@"Please enter your email address before submitting your suggestion."
  104. delegate:nil
  105. cancelButtonTitle:nil
  106. otherButtonTitles:@"OK", nil];
  107. [alert show];
  108. [alert release];
  109. }
  110. }
  111. }
  112. - (void)didCreateUser:(UVUser *)theUser {
  113. [UVSession currentSession].user = theUser;
  114. // token should have been loaded by ResponseDelegate
  115. [[UVSession currentSession].currentToken persist];
  116. [self createSuggestion];
  117. }
  118. - (void)didCreateSuggestion:(UVSuggestion *)theSuggestion {
  119. [self hideActivityIndicator];
  120. NSString *msg = [NSString stringWithFormat:@"Your idea \"%@\" was successfully created.", self.title];
  121. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Success"
  122. message:msg
  123. delegate:nil
  124. cancelButtonTitle:nil
  125. otherButtonTitles:@"OK", nil];
  126. [alert show];
  127. [alert release];
  128. // increment the created suggestions and supported suggestions counts
  129. [UVSession currentSession].user.supportedSuggestionsCount += 1;
  130. [UVSession currentSession].user.createdSuggestionsCount += 1;
  131. // add to this users created suggestions, unless they have never been loaded or are going to be
  132. //[[UVSession currentSession].user.createdSuggestions addObject:theSuggestion];
  133. [UVSession currentSession].user.suggestionsNeedReload = YES;
  134. [UVSession currentSession].clientConfig.forum.currentTopic.suggestionsNeedReload = YES;
  135. // update the remaining votes
  136. [UVSession currentSession].clientConfig.forum.currentTopic.votesRemaining = theSuggestion.votesRemaining;
  137. //[self dismissModalViewControllerAnimated:YES];
  138. [self.navigationController popViewControllerAnimated:YES];
  139. }
  140. - (void)didDiscoverUser:(UVUser *)theUser {
  141. [self hideActivityIndicator];
  142. // add email to user as won't of been returned
  143. theUser.email = self.emailField.text;
  144. UVSignInViewController *signinView = [[UVSignInViewController alloc] initWithUVUser:theUser];
  145. [self.navigationController pushViewController:signinView animated:YES];
  146. [signinView release];
  147. }
  148. - (void)checkEmail {
  149. if (self.emailField.text.length > 0) {
  150. [self showActivityIndicatorWithText:@"Checking..."];
  151. [UVUser discoverWithEmail:emailField.text delegate:self];
  152. }
  153. }
  154. - (void)dismissTextView {
  155. shouldResizeForKeyboard = YES;
  156. [self.textEditor resignFirstResponder];
  157. }
  158. - (void)voteSegmentChanged:(id)sender {
  159. UISegmentedControl *segments = (UISegmentedControl *)sender;
  160. self.numVotes = segments.selectedSegmentIndex + 1;
  161. [self dismissTextView];
  162. }
  163. - (void)contactButtonTapped {
  164. UINavigationController *navController = self.navigationController;
  165. NSArray *viewControllers = [navController viewControllers];
  166. NSMutableArray *newControllers = [NSMutableArray arrayWithCapacity:3];
  167. UIViewController *next = [[UVNewTicketViewController alloc] init];
  168. [newControllers addObject:[viewControllers objectAtIndex:0]];
  169. [newControllers addObject:[viewControllers objectAtIndex:1]];
  170. [newControllers addObject:next];
  171. [navController setViewControllers:newControllers animated:YES];
  172. [next release];
  173. }
  174. - (void)keyboardWillShow:(NSNotification *)aNotification {
  175. if (shouldResizeForKeyboard) {
  176. // Resize the table to account for the keyboard
  177. CGRect keyboardRect = [[[aNotification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
  178. NSTimeInterval animationDuration = [[[aNotification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
  179. CGRect frame = self.tableView.frame;
  180. frame.size.height -= keyboardRect.size.height;
  181. [UIView beginAnimations:@"ResizeForKeyboard" context:nil];
  182. [UIView setAnimationDuration:animationDuration];
  183. self.tableView.frame = frame;
  184. [UIView commitAnimations];
  185. }
  186. }
  187. - (void)keyboardWillHide:(NSNotification *)aNotification {
  188. if (shouldResizeForKeyboard) {
  189. // Resize the table back to the original height
  190. CGRect keyboardRect = [[[aNotification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
  191. NSTimeInterval animationDuration = [[[aNotification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
  192. CGRect frame = self.tableView.frame;
  193. frame.size.height += keyboardRect.size.height;
  194. [UIView beginAnimations:@"ResizeForKeyboard" context:nil];
  195. [UIView setAnimationDuration:animationDuration];
  196. self.tableView.frame = frame;
  197. [UIView commitAnimations];
  198. }
  199. }
  200. #pragma mark ===== UITextFieldDelegate Methods =====
  201. - (void)textFieldDidBeginEditing:(UITextField *)textField {
  202. // Reset didReturn flag. This allows us to distinguish later between the user dismissing the
  203. // keyboard (by tapping on the return key) or tapping on a different text field. In the
  204. // latter case we don't want to grow and re-shrink the table view.
  205. shouldResizeForKeyboard = NO;
  206. // Scroll to the active text field
  207. NSIndexPath *path;
  208. if (textField == self.titleField) {
  209. path = [NSIndexPath indexPathForRow:0 inSection:UV_NEW_SUGGESTION_SECTION_TITLE];
  210. } else {
  211. path = [NSIndexPath indexPathForRow:0 inSection:UV_NEW_SUGGESTION_SECTION_PROFILE];
  212. }
  213. [self.tableView scrollToRowAtIndexPath:path atScrollPosition:UITableViewScrollPositionTop animated:YES];
  214. }
  215. - (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
  216. if (textField==emailField) {
  217. NSLog(@"Check email");
  218. [nameField resignFirstResponder];
  219. [textEditor resignFirstResponder];
  220. [self checkEmail];
  221. }
  222. return YES;
  223. }
  224. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  225. shouldResizeForKeyboard = YES;
  226. [textField resignFirstResponder];
  227. return YES;
  228. }
  229. #pragma mark ===== UVTextEditorDelegate Methods =====
  230. - (void)textEditorDidBeginEditing:(UVTextEditor *)theTextEditor {
  231. shouldResizeForKeyboard = NO;
  232. // Change right bar button to Done, as there's no built-in way to dismiss the
  233. // text view's keyboard.
  234. UIBarButtonItem* saveItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
  235. target:self
  236. action:@selector(dismissTextView)];
  237. self.prevLeftBarButton = self.navigationItem.leftBarButtonItem;
  238. [self.navigationItem setLeftBarButtonItem:saveItem animated:YES];
  239. [saveItem release];
  240. // Scroll to the active text editor
  241. NSIndexPath *path = [NSIndexPath indexPathForRow:0 inSection:UV_NEW_SUGGESTION_SECTION_TEXT];
  242. [self.tableView scrollToRowAtIndexPath:path atScrollPosition:UITableViewScrollPositionTop animated:YES];
  243. }
  244. - (void)textEditorDidEndEditing:(UVTextEditor *)theTextEditor {
  245. self.text = theTextEditor.text;
  246. [self.navigationItem setLeftBarButtonItem:self.prevLeftBarButton animated:YES];
  247. }
  248. - (BOOL)textEditorShouldEndEditing:(UVTextEditor *)theTextEditor {
  249. return YES;
  250. }
  251. #pragma mark ===== table cells =====
  252. - (UITextField *)customizeTextFieldCell:(UITableViewCell *)cell label:(NSString *)label placeholder:(NSString *)placeholder {
  253. cell.textLabel.text = label;
  254. UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(65, 12, 230, 20)];
  255. textField.placeholder = placeholder;
  256. textField.returnKeyType = UIReturnKeyDone;
  257. textField.borderStyle = UITextBorderStyleNone;
  258. textField.delegate = self;
  259. [cell.contentView addSubview:textField];
  260. [textField release];
  261. return textField;
  262. }
  263. - (void)initCellForTitle:(UITableViewCell *)cell indexPath:(NSIndexPath *)indexPath {
  264. [self removeBackgroundFromCell:cell];
  265. CGRect frame = CGRectMake(0, 0, 300, 31);
  266. UITextField *theTitleField = [[UITextField alloc] initWithFrame:frame];
  267. theTitleField.delegate = self;
  268. theTitleField.returnKeyType = UIReturnKeyDone;
  269. theTitleField.autocorrectionType = UITextAutocorrectionTypeYes;
  270. theTitleField.text = self.title;
  271. theTitleField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
  272. theTitleField.clearButtonMode = UITextFieldViewModeWhileEditing;
  273. theTitleField.borderStyle = UITextBorderStyleRoundedRect;
  274. [cell.contentView addSubview:theTitleField];
  275. self.titleField = theTitleField;
  276. [theTitleField release];
  277. }
  278. - (void)initCellForText:(UITableViewCell *)cell indexPath:(NSIndexPath *)indexPath {
  279. CGRect frame = CGRectMake(0, 0, 300, 102);
  280. UVTextEditor *aTextEditor = [[UVTextEditor alloc] initWithFrame:frame];
  281. aTextEditor.delegate = self;
  282. aTextEditor.autocorrectionType = UITextAutocorrectionTypeYes;
  283. aTextEditor.autocapitalizationType = UITextAutocapitalizationTypeSentences;
  284. aTextEditor.minNumberOfLines = 4;
  285. aTextEditor.maxNumberOfLines = 4;
  286. aTextEditor.autoresizesToText = YES;
  287. aTextEditor.backgroundColor = [UIColor clearColor];
  288. aTextEditor.placeholder = @"Description (optional)";
  289. [cell.contentView addSubview:aTextEditor];
  290. self.textEditor = aTextEditor;
  291. [aTextEditor release];
  292. }
  293. - (void)customizeCellForCategory:(UITableViewCell *)cell indexPath:(NSIndexPath *)indexPath {
  294. cell.textLabel.text = @"Category";
  295. cell.detailTextLabel.text = self.category.name;
  296. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  297. }
  298. - (void)initCellForVote:(UITableViewCell *)cell indexPath:(NSIndexPath *)indexPath {
  299. [self removeBackgroundFromCell:cell];
  300. self.numVotes = 1;
  301. NSArray *items = [NSArray arrayWithObjects:@"1 vote", @"2 votes", @"3 votes", nil];
  302. UISegmentedControl *segments = [[UISegmentedControl alloc] initWithItems:items];
  303. segments.frame = CGRectMake(0, 0, 300, 44);
  304. segments.selectedSegmentIndex = 0;
  305. NSInteger votesRemaining = 10;
  306. if ([UVSession currentSession].user)
  307. votesRemaining = [UVSession currentSession].clientConfig.forum.currentTopic.votesRemaining;
  308. for (int i = 0; i < segments.numberOfSegments; i++) {
  309. BOOL enabled = (i + 1) <= votesRemaining;
  310. [segments setEnabled:enabled forSegmentAtIndex:i];
  311. }
  312. if (votesRemaining==0) {
  313. [cell.contentView addSubview:segments];
  314. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 66, 300, 15)];
  315. label.backgroundColor = [UIColor clearColor];
  316. label.textAlignment = UITextAlignmentCenter;
  317. label.font = [UIFont systemFontOfSize:12];
  318. label.text = @"Sorry, you have run out of votes.";
  319. label.textColor = [UVStyleSheet darkRedColor];
  320. [cell.contentView addSubview:label];
  321. [label release];
  322. } else {
  323. [segments addTarget:self action:@selector(voteSegmentChanged:) forControlEvents:UIControlEventValueChanged];
  324. [cell.contentView addSubview:segments];
  325. }
  326. [segments release];
  327. }
  328. - (void)initCellForName:(UITableViewCell *)cell indexPath:(NSIndexPath *)indexPath {
  329. self.nameField = [self customizeTextFieldCell:cell label:@"Name" placeholder:@"Anonymous"];
  330. }
  331. - (void)initCellForEmail:(UITableViewCell *)cell indexPath:(NSIndexPath *)indexPath {
  332. self.emailField = [self customizeTextFieldCell:cell label:@"Email" placeholder:@"Required"];
  333. self.emailField.keyboardType = UIKeyboardTypeEmailAddress;
  334. self.emailField.autocorrectionType = UITextAutocorrectionTypeNo;
  335. self.emailField.autocapitalizationType = UITextAutocapitalizationTypeNone;
  336. }
  337. - (void)initCellForSubmit:(UITableViewCell *)cell indexPath:(NSIndexPath *)indexPath {
  338. [self removeBackgroundFromCell:cell];
  339. NSInteger votesRemaining = 10;
  340. if ([UVSession currentSession].user)
  341. votesRemaining = [UVSession currentSession].clientConfig.forum.currentTopic.votesRemaining;
  342. if (votesRemaining!=0) {
  343. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  344. button.frame = CGRectMake(0, 0, 300, 42);
  345. button.titleLabel.font = [UIFont boldSystemFontOfSize:18];
  346. button.titleLabel.textColor = [UIColor whiteColor];
  347. [button setTitle:@"Create idea" forState:UIControlStateNormal];
  348. [button setBackgroundImage:[UIImage imageNamed:@"uv_primary_button_green.png"] forState:UIControlStateNormal];
  349. [button setBackgroundImage:[UIImage imageNamed:@"uv_primary_button_green_active.png"] forState:UIControlStateHighlighted];
  350. [button addTarget:self action:@selector(createButtonTapped) forControlEvents:UIControlEventTouchUpInside];
  351. [cell.contentView addSubview:button];
  352. }
  353. }
  354. #pragma mark ===== UITableViewDataSource Methods =====
  355. - (NSInteger)section:(NSIndexPath *)indexPath {
  356. if (self.shouldShowCategories) {
  357. return indexPath.section;
  358. } else {
  359. return indexPath.section >= UV_NEW_SUGGESTION_SECTION_CATEGORY ? indexPath.section + 1 : indexPath.section;
  360. }
  361. }
  362. - (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  363. NSString *identifier = @"";
  364. UITableViewCellStyle style = UITableViewCellStyleDefault;
  365. BOOL selectable = NO;
  366. switch ([self section:indexPath]) {
  367. case UV_NEW_SUGGESTION_SECTION_TITLE:
  368. identifier = @"Title";
  369. break;
  370. case UV_NEW_SUGGESTION_SECTION_TEXT:
  371. identifier = @"Text";
  372. break;
  373. case UV_NEW_SUGGESTION_SECTION_CATEGORY:
  374. identifier = @"Category";
  375. style = UITableViewCellStyleValue1;
  376. selectable = self.forum.availableCategories && [self.forum.availableCategories count] > 0;
  377. break;
  378. case UV_NEW_SUGGESTION_SECTION_VOTE:
  379. identifier = @"Vote";
  380. break;
  381. case UV_NEW_SUGGESTION_SECTION_PROFILE:
  382. identifier = indexPath.row == 0 ? @"Email" : @"Name";
  383. break;
  384. case UV_NEW_SUGGESTION_SECTION_SUBMIT:
  385. identifier = @"Submit";
  386. break;
  387. }
  388. return [self createCellForIdentifier:identifier
  389. tableView:theTableView
  390. indexPath:indexPath
  391. style:style
  392. selectable:selectable];
  393. }
  394. - (NSInteger)numberOfSectionsInTableView:(UITableView *)theTableView {
  395. return self.shouldShowCategories ? 6 : 5;
  396. }
  397. - (NSInteger)tableView:(UITableView *)theTableView numberOfRowsInSection:(NSInteger)section {
  398. if (section == UV_NEW_SUGGESTION_SECTION_PROFILE) {
  399. return [[UVSession currentSession].user hasEmail] ? 0 : 2;
  400. } else {
  401. return 1;
  402. }
  403. }
  404. #pragma mark ===== UITableViewDelegate Methods =====
  405. - (CGFloat)tableView:(UITableView *)theTableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  406. switch ([self section:indexPath]) {
  407. case UV_NEW_SUGGESTION_SECTION_TITLE:
  408. return 31;
  409. case UV_NEW_SUGGESTION_SECTION_TEXT:
  410. return 102;
  411. case UV_NEW_SUGGESTION_SECTION_VOTE:
  412. return 61;
  413. case UV_NEW_SUGGESTION_SECTION_SUBMIT:
  414. return 42;
  415. default:
  416. return 44;
  417. }
  418. }
  419. - (CGFloat)tableView:(UITableView *)theTableView heightForHeaderInSection:(NSInteger)section {
  420. switch (section) {
  421. case UV_NEW_SUGGESTION_SECTION_TITLE:
  422. return 10.0;
  423. case UV_NEW_SUGGESTION_SECTION_PROFILE:
  424. return 20.0;
  425. default:
  426. return 0.0;
  427. }
  428. }
  429. - (UIView *)tableView:(UITableView *)theTableView viewForHeaderInSection:(NSInteger)section {
  430. CGFloat height = [self tableView:theTableView heightForHeaderInSection:section];
  431. return [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, height)] autorelease];
  432. }
  433. - (void)tableView:(UITableView *)theTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  434. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  435. if (indexPath.section == UV_NEW_SUGGESTION_SECTION_CATEGORY && self.shouldShowCategories) {
  436. [self dismissTextView];
  437. UIViewController *next = [[UVCategorySelectViewController alloc] initWithForum:self.forum andSelectedCategory:self.category];
  438. [self.navigationController pushViewController:next animated:YES];
  439. [next release];
  440. }
  441. }
  442. #pragma mark ===== Basic View Methods =====
  443. - (void)dismissController {
  444. // reset nav
  445. [self.navigationItem setLeftBarButtonItem:self.prevLeftBarButton animated:YES];
  446. [self.navigationController popViewControllerAnimated:YES];
  447. }
  448. - (void)loadView {
  449. [super loadView];
  450. self.navigationItem.title = @"New Suggestion";
  451. CGRect frame = [self contentFrame];
  452. UIView *contentView = [[UIView alloc] initWithFrame:frame];
  453. UITableView *theTableView = [[UITableView alloc] initWithFrame:contentView.bounds style:UITableViewStyleGrouped];
  454. theTableView.dataSource = self;
  455. theTableView.delegate = self;
  456. theTableView.sectionFooterHeight = 0.0;
  457. theTableView.backgroundColor = [UIColor clearColor];
  458. UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
  459. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, 320, 15)];
  460. label.text = @"Want to send a private message instead?";
  461. label.textAlignment = UITextAlignmentCenter;
  462. label.textColor = [UVStyleSheet dimBlueColor];
  463. label.backgroundColor = [UIColor clearColor];
  464. label.font = [UIFont systemFontOfSize:13];
  465. [footer addSubview:label];
  466. [label release];
  467. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  468. button.frame = CGRectMake(0, 25, 320, 15);
  469. NSString *buttonTitle = [NSString stringWithFormat:@"Contact %@", [UVSession currentSession].clientConfig.subdomain.name];
  470. [button setTitle:buttonTitle forState:UIControlStateNormal];
  471. [button setTitleColor:[UVStyleSheet dimBlueColor] forState:UIControlStateNormal];
  472. button.backgroundColor = [UIColor clearColor];
  473. button.showsTouchWhenHighlighted = YES;
  474. button.titleLabel.font = [UIFont boldSystemFontOfSize:13];
  475. [button addTarget:self action:@selector(contactButtonTapped) forControlEvents:UIControlEventTouchUpInside];
  476. [footer addSubview:button];
  477. theTableView.tableFooterView = footer;
  478. [footer release];
  479. self.tableView = theTableView;
  480. [contentView addSubview:theTableView];
  481. [theTableView release];
  482. self.view = contentView;
  483. [contentView release];
  484. [self addGradientBackground];
  485. }
  486. - (void)viewDidAppear:(BOOL)animated {
  487. shouldResizeForKeyboard = YES;
  488. }
  489. - (void)viewWillAppear:(BOOL)animated {
  490. // Listen for keyboard hide/show notifications
  491. [super viewWillAppear:animated];
  492. if (self.needsReload) {
  493. [self.tableView reloadData];
  494. self.needsReload = NO;
  495. }
  496. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
  497. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
  498. }
  499. - (void)viewDidDisappear:(BOOL)animated {
  500. [super viewDidDisappear:animated];
  501. [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
  502. [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
  503. }
  504. - (void)didReceiveMemoryWarning {
  505. // Releases the view if it doesn't have a superview.
  506. [super didReceiveMemoryWarning];
  507. // Release any cached data, images, etc that aren't in use.
  508. }
  509. - (void)viewDidUnload {
  510. // Release any retained subviews of the main view.
  511. // e.g. self.myOutlet = nil;
  512. self.tableView = nil;
  513. self.textEditor = nil;
  514. self.titleField = nil;
  515. self.nameField = nil;
  516. self.emailField = nil;
  517. self.prevLeftBarButton = nil;
  518. }
  519. - (void)dealloc {
  520. [super dealloc];
  521. }
  522. @end