PostQues.m 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. //
  2. #import "PostQues.h"
  3. @interface PostQues ()<UITextViewDelegate>
  4. {
  5. UITextView* textV;
  6. UITextField* textF;
  7. UILabel* pHolder;
  8. }
  9. @end
  10. @implementation PostQues
  11. - (void)viewDidLoad {
  12. [super viewDidLoad];
  13. [self myInit];
  14. }
  15. - (void)didReceiveMemoryWarning {
  16. [super didReceiveMemoryWarning];
  17. }
  18. #pragma mark -
  19. -(void)myInit
  20. {
  21. [self configNavigationBar];
  22. [self setTitle:@"提问"];
  23. [self.view setBackgroundColor:backGroundColor];
  24. UIBarButtonItem* bbi = [[UIBarButtonItem alloc] initWithTitle:@"提交" style:UIBarButtonItemStylePlain target:self action:@selector(uploadAppQuestion)];
  25. [bbi setTintColor:defGreen];
  26. self.navigationItem.rightBarButtonItem = bbi;
  27. CGFloat y,h;
  28. h = 120;
  29. y = 0;
  30. UIView* vi;
  31. vi = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, h)];
  32. [vi setBackgroundColor:[UIColor whiteColor]];
  33. [self.view addSubview:vi];
  34. UITextView* tev = [[UITextView alloc] initWithFrame:CGRectMake(10, 10, kSize.width -20 , h-20)];
  35. [self.view addSubview:tev];
  36. textV= tev;
  37. [tev setFont:[UIFont scaleSize:NormalFont]];
  38. [tev setDelegate:self];
  39. UILabel* label ;
  40. label = [[UILabel alloc] initWithFrame:CGRectMake(5, 0, 100, 30)];
  41. [label setText:@"输入问题"];
  42. [label setFont:[UIFont scaleSize:NormalFont]];
  43. [textV addSubview:label];
  44. [label setTextColor:RGB_COLOR(197, 197, 202)];
  45. pHolder = label;
  46. y+= h +10;
  47. h = 50;
  48. vi = [[UIView alloc] initWithFrame:CGRectMake(0, y, kSize.width, h)];
  49. [vi setBackgroundColor:[UIColor whiteColor]];
  50. [self.view addSubview:vi];
  51. UITextField* tf = [[UITextField alloc] initWithFrame:CGRectMake( 10, 0, kSize.width -20, h)];
  52. [tf setPlaceholder:@"输入您的姓名"];
  53. [tf setFont:[UIFont scaleSize:NormalFont]];
  54. [vi addSubview:tf];
  55. textF = tf;
  56. }
  57. -(void)preFreshBlock:(void (^)(void))block
  58. {
  59. preFresh = block;
  60. }
  61. -(void)uploadAppQuestion
  62. {
  63. if (textV.text.length < 6) {
  64. ShowMsg(@"最少写6个字");
  65. return;
  66. }
  67. // NSLog(@"uploadAppQuestion");
  68. // NSLog(@"->%@",textV.text);
  69. // NSLog(@"->%@",textF.text);
  70. if (![Util connectedToNetWork]) {
  71. showMsgUnconnect();
  72. return;
  73. }
  74. NSMutableArray *arr=[NSMutableArray array];
  75. [arr addPro:@"user" Value:defUser.userDict[@"id"]];
  76. [arr addPro:@"userName" Value:defUser.userDict[@"userName"]];
  77. [arr addPro:@"content" Value:textV.text];
  78. [arr addPro:@"jxbh" Value:_jxbh];//14000163
  79. [arr addPro:@"mobile" Value:defUser.userTel];
  80. NSString* method = @"uploadAppQuestion";
  81. [MBProgressHUD showLoadToView:self.view];
  82. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  83. [MBProgressHUD hideHUDForView:self.view];
  84. if (!root)
  85. {
  86. ShowMsgFailed();
  87. return;
  88. }
  89. NSString* code = root[@"code"];
  90. if ( 1 == code.intValue ) {
  91. ShowMsgFailed();
  92. return;
  93. }
  94. if (preFresh) {
  95. preFresh();
  96. }
  97. ShowMsgSuc();
  98. [textF resignFirstResponder];
  99. [textV resignFirstResponder];
  100. [self.navigationController popViewControllerAnimated:YES];
  101. }];
  102. }
  103. -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
  104. {
  105. [self.view endEditing:YES];
  106. }
  107. #pragma mark -
  108. - (void)textViewDidChange:(UITextView *)textView
  109. {
  110. if (textView.text.length > 0) {
  111. pHolder.hidden = YES;
  112. }
  113. }
  114. @end