AddPictureViewController.m 25.3 KB
Newer Older
admin's avatar
admin committed
1 2 3 4 5 6 7 8 9 10
//
//  AddPictureViewController.m
//  redstar
//
//  Created by admin on 15/12/7.
//  Copyright © 2015年 ZWF. All rights reserved.
//

#import "AddPictureViewController.h"
#import "AddPictureTableCell.h"
admin's avatar
admin committed
11 12
#import "AddButtonTableViewCell.h"
#import "AddPicTextTableViewCell.h"
admin's avatar
admin committed
13
#import "CheckPicViewController.h"
admin's avatar
admin committed
14
#import "LargePictureViewController.h"
admin's avatar
admin committed
15 16

#import "HttpClient.h"
admin's avatar
admin committed
17 18
#import "UIImage+Fit.h"
#import "CommonFunc.h"
admin's avatar
admin committed
19

20 21
#import <MBProgressHUD.h>

admin's avatar
admin committed
22
#define kAddPicTableViewCell @"addPicTableCell"
admin's avatar
admin committed
23 24
#define kAddPicTextTableViewCell @"addPicTextTableCell"
#define kAddButtonCell @"addButtonTableViewCell"
admin's avatar
admin committed
25

admin's avatar
admin committed
26
@interface AddPictureViewController () <UITableViewDelegate, UITableViewDataSource, UINavigationControllerDelegate, UIImagePickerControllerDelegate, UIActionSheetDelegate, UIAlertViewDelegate, UITextViewDelegate>
admin's avatar
admin committed
27 28
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *imageNameArray;
29 30
@property (nonatomic, strong) NSMutableArray *textArray;

admin's avatar
admin committed
31 32 33 34

@property (nonatomic, assign) int rowNumber;
@property (nonatomic, strong) UIView *footView;
@property (nonatomic, strong) UIButton *reportButton;
admin's avatar
admin committed
35
@property (nonatomic, strong) UIActionSheet *selectActionSheet;
admin's avatar
admin committed
36

admin's avatar
admin committed
37 38
@property (nonatomic, copy) NSString *praiseUuid;

admin's avatar
admin committed
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
@end

@implementation AddPictureViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    UILabel *customLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 40, 30)];
    [customLab setTextColor:[UIColor whiteColor]];
    [customLab setText:@"新增口碑"];
    customLab.font = [UIFont boldSystemFontOfSize:19];
    self.navigationItem.titleView = customLab;
    
    
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(0, 0, 30, 44);
    
    [backBtn setImage:[UIImage imageNamed:@"back_btn"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(doBack:) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
    self.navigationItem.leftBarButtonItem = backItem;
    
    
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableView.tableFooterView = self.footView;
    
    [self.reportButton addTarget:self action:@selector(uploadInspect:) forControlEvents:UIControlEventTouchUpInside];

    _rowNumber = 2;
admin's avatar
admin committed
72
    self.imageNameArray = [NSMutableArray array];
73
    self.textArray = [NSMutableArray array];
admin's avatar
admin committed
74 75 76 77 78
}

#pragma mark - Private Mothods
- (void)uploadInspect:(UIButton *)sender
{
admin's avatar
admin committed
79 80 81 82 83 84 85 86 87 88
    if (_imageNameArray.count == 0) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请至少添加一组图片和文字!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
        [alert show];
        return;
    }
    // 提示框
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"您确定要上报口碑吗?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    alert.tag = 334281;
    alert.delegate = self;
    [alert show];
admin's avatar
admin committed
89 90 91 92
}

- (void)doBack:(id)sender
{
admin's avatar
admin committed
93 94 95 96
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"您确定要放弃编辑当前图说口碑吗?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    alert.tag = 9211232;
    [alert show];
    
admin's avatar
admin committed
97 98 99 100
}

- (void)createImagePicker:(UIButton *)sender
{
admin's avatar
admin committed
101 102 103 104 105 106
    self.selectActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"直接拍照上传", @"从本地相册选择", nil];
    _selectActionSheet.delegate = self;
    _selectActionSheet.tag = 999283;
    [_selectActionSheet showInView:self.view];
    
    
admin's avatar
admin committed
107 108 109
    if (sender.tag == 2201) {
        _rowNumber++;
    }
admin's avatar
admin committed
110 111 112 113 114 115 116 117 118 119 120 121 122 123
}

- (void)addPicText:(UIButton *)sender
{
    NSDate *date = [NSDate date];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"YYYY-MM-dd+hh:mm:ss"];
    NSString *dateString = [dateFormatter stringFromDate:date];
    
    NSString *operId = [[NSUserDefaults standardUserDefaults] objectForKey:@"user_code"];
    NSString *operName = [[NSUserDefaults standardUserDefaults] objectForKey:@"user_name"];
    
    if (_rowNumber == 2) {
        AddPictureTableCell *cell = [_tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
admin's avatar
admin committed
124 125
        cell.titleTextView.delegate = self;
        cell.contentTextView.delegate = self;
admin's avatar
admin committed
126 127 128 129 130
        if (cell.titleTextView.text.length == 0 || cell.contentTextView.text.length == 0) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"标题、问题与建议描述不能为空!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
            [alert show];
            return;
        } else {
131
            [MBProgressHUD showHUDAddedTo:self.view animated:YES];
admin's avatar
admin committed
132 133 134 135 136
            NSString *url = [NSString stringWithFormat:@"%@%@%@&operId=%@&operName=%@", kRedStarURL, kSavePicturePraiseURL,dateString, operId, operName];
            url = [url stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
            HttpClient *http1 = [[HttpClient alloc] initWithUrl:url];
            NSDictionary *parameters = @{
                                         @"title":cell.contentTextView.text,
admin's avatar
admin committed
137
                                         @"content":cell.titleTextView.text,
admin's avatar
admin committed
138
                                         @"type":self.category
admin's avatar
admin committed
139 140
                                         };
            [http1 savePicturePraiseWithParameters:parameters completion:^(id response, NSError *error) {
admin's avatar
admin committed
141
                _praiseUuid = response[@"data"];
142 143 144 145 146
                if ([response[@"success"] boolValue]) {
                    NSLog(@"失败");
                }
                [MBProgressHUD hideHUDForView:self.view animated:YES];

admin's avatar
admin committed
147 148
            }];
        }
149 150
        _rowNumber++;
        [self.tableView reloadData];
admin's avatar
admin committed
151
        
admin's avatar
admin committed
152 153 154 155 156 157 158 159
    } else {
        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:(_rowNumber - 2) inSection:0];
        AddPicTextTableViewCell *cell = [_tableView cellForRowAtIndexPath:indexPath];
        
        NSString *url = [NSString stringWithFormat:@"%@%@%@/submit_attachment?time=%@&operId=%@&operName=%@", kRedStarURL, kUpLoadPictureURL, _praiseUuid ,dateString, operId, operName];
        url = [url stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
        HttpClient *http1 = [[HttpClient alloc] initWithUrl:url];
        
160
        if ((_imageNameArray.count == _rowNumber - 2) && cell.titleTextView.text.length != 0 ) {
161 162 163
            
            [self.textArray addObject:cell.titleTextView.text];
            
164 165 166
            NSString *imageName = _imageNameArray[_rowNumber - 3];
            NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName];
            UIImage *image = [UIImage imageWithContentsOfFile:fullPath];
admin's avatar
admin committed
167
            NSData *imageData = UIImageJPEGRepresentation(image, 0.01);
168 169 170 171 172 173
            NSString *imageBase64 = [imageData base64EncodedStringWithOptions:0];
            NSDictionary *parameters = @{
                                         @"description":cell.titleTextView.text,
                                         @"fileName":imageName,
                                         @"fileContent":imageBase64
                                         };
174
            [MBProgressHUD showHUDAddedTo:self.view animated:YES];
175
            [http1 upLoadPraisePictureWithParameters:parameters completion:^(id response, NSError *error) {
176 177 178 179 180 181 182 183 184 185 186
                [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
                
                if ([response[@"success"] boolValue]) {
                    _rowNumber++;
                    [self.tableView reloadData];
                } else {
                    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"当前图片上传失败,请重新上传!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
                    [alert show];
                    return ;
                }

187
            }];
188
            
189 190 191 192
        } else {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"必须有图片和图片说明!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
            [alert show];
        }
admin's avatar
admin committed
193
    }
194 195
    
        
admin's avatar
admin committed
196 197 198
}

- (void)saveImage:(UIImage *)currentImage {
admin's avatar
admin committed
199
    NSData *imageData = UIImageJPEGRepresentation(currentImage, 0.01);
admin's avatar
admin committed
200
    NSString *imageName = [CommonFunc md5Data:imageData];
admin's avatar
admin committed
201 202 203 204 205 206 207 208
    [_imageNameArray addObject:imageName];
    
    // 获取沙盒目录
    NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName];
    // 将图片写入文件
    [imageData writeToFile:fullPath atomically:NO];
}

admin's avatar
admin committed
209 210
- (void)showBigPic:(UIButton *)sender
{
admin's avatar
admin committed
211 212 213 214 215 216 217 218 219 220 221 222 223
    AddPicTextTableViewCell *cell = (AddPicTextTableViewCell *)sender.superview.superview;
    NSIndexPath *indexPath = [_tableView indexPathForCell:cell];
    NSInteger index = indexPath.row - 1;
    
    LargePictureViewController *largeVC = [[LargePictureViewController alloc] init];
    largeVC.index = index;
    largeVC.pictureSaveMode = PictureLocalMode;
    largeVC.allImageArray = _imageNameArray;
    [self.navigationController pushViewController:largeVC animated:YES];
    
//    CheckPicViewController *checkVC = [[CheckPicViewController alloc] init];
//    checkVC.checkImage = sender.imageView.image;
//    [self.navigationController pushViewController:checkVC animated:YES];
admin's avatar
admin committed
224 225
}

admin's avatar
admin committed
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
#pragma mark - UItextView
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
     AddPictureTableCell *cell = [_tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
    if (![text isEqualToString:@""]) {
        if (textView.tag == 9991) {
            cell.placeholderLabel1.hidden = YES;
        } else {
            cell.placeholderLabel2.hidden = YES;
        }
    }
    
    if ([text isEqualToString:@""] && range.location == 0 && range.length == 1) {
        if (textView.tag == 9991) {
            cell.placeholderLabel1.hidden = NO;
        } else {
            cell.placeholderLabel2.hidden = NO;
        }
    }
    
    if ([text isEqualToString:@"\n"]) {
        [cell.titleTextView resignFirstResponder];
        [cell.contentTextView resignFirstResponder];
        
        if (textView.tag == 9991) {
            if (textView.text.length != 0) {
                cell.placeholderLabel1.hidden = YES;
            } else {
                cell.placeholderLabel1.hidden = NO;
            }
        } else {
            if (textView.text.length != 0) {
                cell.placeholderLabel2.hidden = YES;
            } else {
                cell.placeholderLabel2.hidden = NO;
            }
        }
        return NO;
    }
    
    return YES;
}


admin's avatar
admin committed
270 271 272 273 274 275 276 277 278 279 280 281 282
#pragma mark - UIImagePickerController 代理方法
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    [self saveImage:image];
    
    // 退出图片选择控制器
    [picker dismissViewControllerAnimated:YES completion:^{
        [self.tableView reloadData];
    }];
    
}

admin's avatar
admin committed
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312


#pragma mark - UIActionSheetDelegate

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if (actionSheet.tag == 999283) {
        if (buttonIndex == 0) {
            if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"找不到相机" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
                [alert show];
            } else {
                UIImagePickerController *picker = [[UIImagePickerController alloc] init];
                picker.delegate = self;
                picker.sourceType = UIImagePickerControllerSourceTypeCamera;
                picker.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
                picker.videoQuality = UIImagePickerControllerQualityTypeLow;
                [self presentViewController:picker animated:YES completion:nil];
            }
        } else if (buttonIndex == 1){
            UIImagePickerController *picker = [[UIImagePickerController alloc] init];
            picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            picker.delegate = self;
            //设置选择后的图片可被编辑
            picker.allowsEditing = YES;
            [self presentViewController:picker animated:YES completion:nil];
        }
    }
}

admin's avatar
admin committed
313 314 315 316 317 318
#pragma mark - UIAlertViewDelegte
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (alertView.tag == 334281) {
        if (buttonIndex == 1) {
            
319
            [MBProgressHUD showHUDAddedTo:self.view animated:YES];
admin's avatar
admin committed
320 321 322 323 324 325 326
            NSDate *date = [NSDate date];
            NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
            [dateFormatter setDateFormat:@"YYYY-MM-dd+hh:mm:ss"];
            NSString *dateString = [dateFormatter stringFromDate:date];
            
            NSString *operId = [[NSUserDefaults standardUserDefaults] objectForKey:@"user_code"];
            NSString *operName = [[NSUserDefaults standardUserDefaults] objectForKey:@"user_name"];
admin's avatar
admin committed
327 328

            NSIndexPath *indexPath = [NSIndexPath indexPathForRow:(_rowNumber - 2) inSection:0];
329 330
            AddPicTextTableViewCell *cell = [_tableView cellForRowAtIndexPath:indexPath];
            if (_imageNameArray.count == _rowNumber - 2 || cell.titleTextView.text.length != 0) {
admin's avatar
admin committed
331 332 333 334 335 336 337 338
                
                NSString *urlStr = [NSString stringWithFormat:@"%@%@%@/submit_attachment?time=%@&operId=%@&operName=%@", kRedStarURL, kUpLoadPictureURL, _praiseUuid ,dateString, operId, operName];
                urlStr = [urlStr stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
                HttpClient *httpClinet = [[HttpClient alloc] initWithUrl:urlStr];
                
                NSString *imageName = _imageNameArray[_rowNumber - 3];
                NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName];
                UIImage *image = [UIImage imageWithContentsOfFile:fullPath];
admin's avatar
admin committed
339
                NSData *imageData = UIImageJPEGRepresentation(image, 0.01);
admin's avatar
admin committed
340 341 342 343 344 345 346 347 348 349 350 351 352
                NSString *imageBase64 = [imageData base64EncodedStringWithOptions:0];
                NSDictionary *parameters = @{
                                             @"description":cell.titleTextView.text,
                                             @"fileName":imageName,
                                             @"fileContent":imageBase64
                                             };
                [httpClinet upLoadPraisePictureWithParameters:parameters completion:^(id response, NSError *error) {
                    
                    
                    NSString *url = [NSString stringWithFormat:@"%@%@%@/submit?time=%@&operId=%@&operName=%@", kRedStarURL, kSubmitPicturePraiseURL,_praiseUuid, dateString, operId, operName];
                    url = [url stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
                    HttpClient *http1 = [[HttpClient alloc] initWithUrl:url];
                    [http1 submitPicturePraiseWithCompletion:^(id response, NSError *error) {
admin's avatar
admin committed
353
                        if ([response[@"success"] boolValue]) {
354 355 356 357 358 359
                            UIAlertView *alertt = [[UIAlertView alloc] initWithTitle:@"提示" message:@"新增口碑成功!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
                            alertt.tag = 893323;
                            [alertt show];
                        } else {
                            UIAlertView *alertt = [[UIAlertView alloc] initWithTitle:@"警告" message:@"新增口碑失败!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
                            [alertt show];
admin's avatar
admin committed
360
                        }
361
                        [MBProgressHUD hideHUDForView:self.view animated:YES];
admin's avatar
admin committed
362 363 364 365 366 367 368 369 370
                    }];
                }];
            }
        }
    }
    
    if (alertView.tag == 9211232) {
        if (buttonIndex == 1) {
            [self.navigationController popViewControllerAnimated:YES];
admin's avatar
admin committed
371 372
        }
    }
373 374 375 376 377 378 379 380 381 382
    
    if (alertView.tag == 893323) {
        if (buttonIndex == 0) {
            if (_delegate && [_delegate respondsToSelector:@selector(reloadList)]) {
                [_delegate reloadList];
            }
            [self.navigationController popViewControllerAnimated:YES];
        }
    }
    
admin's avatar
admin committed
383 384 385
}


admin's avatar
admin committed
386

admin's avatar
admin committed
387 388 389 390 391 392 393 394 395 396 397 398 399
#pragma mark - UITableView Delegate/DataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _rowNumber;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        AddPictureTableCell *cell=[tableView dequeueReusableCellWithIdentifier:kAddPicTableViewCell];
        if (!cell) {
            cell = [[AddPictureTableCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kAddPicTableViewCell];
        }
admin's avatar
admin committed
400 401
        cell.titleTextView.delegate = self;
        cell.contentTextView.delegate = self;
admin's avatar
admin committed
402 403 404
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    } else if (indexPath.row == _rowNumber - 1) {
admin's avatar
admin committed
405 406 407 408 409 410 411 412 413 414 415 416 417
        AddButtonTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:kAddButtonCell];
        if (!cell) {
            cell = [[AddButtonTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kAddButtonCell];
        }
        [cell.addButton addTarget:self action:@selector(addPicText:) forControlEvents:UIControlEventTouchUpInside];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    } else {
        AddPicTextTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:kAddPicTextTableViewCell];
        if (!cell) {
            cell = [[AddPicTextTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kAddPicTextTableViewCell];
        }
        
admin's avatar
admin committed
418
        if (_rowNumber - 2 == _imageNameArray.count) {
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443
            
            if (indexPath.row == _rowNumber - 2) {
                
                NSString *imageName = _imageNameArray[indexPath.row - 1];
                NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName];
                UIImage *image = [UIImage imageWithContentsOfFile:fullPath];
                UIImage *image00 = [UIImage image:image fillSize:CGSizeMake((kScreenWidth - 60) / 2, 90)];
                [cell.photoButton setImage:image00 forState:UIControlStateNormal];
                [cell.photoButton removeTarget:self action:@selector(createImagePicker:) forControlEvents:UIControlEventTouchUpInside];
                [cell.photoButton addTarget:self action:@selector(showBigPic:) forControlEvents:UIControlEventTouchUpInside];
                cell.titleTextView.userInteractionEnabled = YES;
                cell.titleTextView.text = @"";
            } else {
                NSString *imageName = _imageNameArray[indexPath.row - 1];
                NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName];
                UIImage *image = [UIImage imageWithContentsOfFile:fullPath];
                UIImage *image00 = [UIImage image:image fillSize:CGSizeMake((kScreenWidth - 60) / 2, 90)];
                [cell.photoButton setImage:image00 forState:UIControlStateNormal];
                [cell.photoButton removeTarget:self action:@selector(createImagePicker:) forControlEvents:UIControlEventTouchUpInside];
                [cell.photoButton addTarget:self action:@selector(showBigPic:) forControlEvents:UIControlEventTouchUpInside];
                NSString *textStr = _textArray[indexPath.row - 1];
                cell.titleTextView.text = textStr;
                
            }
            
admin's avatar
admin committed
444
        } else {
admin's avatar
admin committed
445 446
            if (indexPath.row == _rowNumber - 2) {
                [cell.photoButton setImage:[UIImage imageNamed:@"add-photo_icon"] forState:UIControlStateNormal];
admin's avatar
admin committed
447 448
                [cell.photoButton removeTarget:self action:@selector(showBigPic:) forControlEvents:UIControlEventTouchUpInside];
                [cell.photoButton addTarget:self action:@selector(createImagePicker:) forControlEvents:UIControlEventTouchUpInside];
449
                cell.titleTextView.text = @"";
admin's avatar
admin committed
450

admin's avatar
admin committed
451 452 453 454
            } else {
                NSString *imageName = _imageNameArray[indexPath.row - 1];
                NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName];
                UIImage *image = [UIImage imageWithContentsOfFile:fullPath];
admin's avatar
admin committed
455
                UIImage *image00 = [UIImage image:image fillSize:CGSizeMake((kScreenWidth - 60) / 2, 110)];
admin's avatar
admin committed
456
                [cell.photoButton setImage:image00 forState:UIControlStateNormal];
admin's avatar
admin committed
457 458 459
                [cell.photoButton removeTarget:self action:@selector(createImagePicker:) forControlEvents:UIControlEventTouchUpInside];
                [cell.photoButton addTarget:self action:@selector(showBigPic:) forControlEvents:UIControlEventTouchUpInside];
                cell.titleTextView.userInteractionEnabled = NO;
460 461
                NSString *textStr = _textArray[indexPath.row - 1];
                cell.titleTextView.text = textStr;
admin's avatar
admin committed
462
            }
admin's avatar
admin committed
463
        }
admin's avatar
admin committed
464 465 466 467
        return cell;
    }   
}

admin's avatar
admin committed
468 469 470 471 472 473 474 475 476 477 478 479 480
#pragma mark - lazy loading
- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableView.translatesAutoresizingMaskIntoConstraints = NO;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.showsHorizontalScrollIndicator = NO;
        _tableView.rowHeight = UITableViewAutomaticDimension;
        _tableView.estimatedRowHeight = 100.0;
        [_tableView registerClass:[AddPictureTableCell class] forCellReuseIdentifier:kAddPicTableViewCell];
admin's avatar
admin committed
481 482
        [_tableView registerClass:[AddPicTextTableViewCell class] forCellReuseIdentifier:kAddPicTextTableViewCell];
        [_tableView registerClass:[AddButtonTableViewCell class] forCellReuseIdentifier:kAddButtonCell];
admin's avatar
admin committed
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533
        [self.view addSubview:_tableView];
        
        NSLayoutConstraint *tableTop = [NSLayoutConstraint constraintWithItem:_tableView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1.0 constant:0];
        [self.view addConstraint:tableTop];
        
        NSLayoutConstraint *tableLeft = [NSLayoutConstraint constraintWithItem:_tableView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
        [self.view addConstraint:tableLeft];
        
        NSLayoutConstraint *tableRight = [NSLayoutConstraint constraintWithItem:_tableView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeRight multiplier:1.0 constant:0];
        [self.view addConstraint:tableRight];
        
        NSLayoutConstraint *tableBottom = [NSLayoutConstraint constraintWithItem:_tableView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
        [self.view addConstraint:tableBottom];
    }
    return _tableView;
}

- (UIView *)footView
{
    if (!_footView) {
        _footView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 60)];
    }
    return _footView;
}

- (UIButton *)reportButton
{
    if (!_reportButton) {
        _reportButton = [[UIButton alloc] init];
        _reportButton.translatesAutoresizingMaskIntoConstraints = NO;
        _reportButton.backgroundColor = kNavigationBarColor;
        [_reportButton setTitle:@"上报口碑" forState:UIControlStateNormal];
        [self.footView addSubview:_reportButton];
        
        NSLayoutConstraint *reportTop = [NSLayoutConstraint constraintWithItem:_reportButton attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.footView attribute:NSLayoutAttributeTop multiplier:1.0 constant:10];
        [self.footView addConstraint:reportTop];
        
        NSLayoutConstraint *reportLeft = [NSLayoutConstraint constraintWithItem:_reportButton attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.footView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:20];
        [self.footView addConstraint:reportLeft];
        
        NSLayoutConstraint *reportWidth = [NSLayoutConstraint constraintWithItem:_reportButton attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:kScreenWidth - 40];
        [self.footView addConstraint:reportWidth];
        
        NSLayoutConstraint *tableHeight = [NSLayoutConstraint constraintWithItem:_reportButton attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:40];
        [self.footView addConstraint:tableHeight];
    }
    return _reportButton;
}


@end