// // MessageBoxViewController.m // kneet2 // // Created by Jason Lee on 10/14/15. // Copyright © 2015 ntels. All rights reserved. // #import "MessageBoxViewController.h" #import "RequestHandler.h" #import "ModeModel.h" #import "CustomTableView.h" #import "CustomLabel.h" #import "CustomButton.h" #import "CustomImageView.h" @implementation MessageBoxTableViewCell @end @interface MessageBoxViewController () { NSMutableArray *_personalNoticeList; NSString *_pagingId, *_pagingType; } @end #pragma mark - Class Definition @implementation MessageBoxViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. _personalNoticeList = (NSMutableArray *)[[NSMutableArray alloc] init]; [self initUI]; [self prepareViewDidLoad]; } - (void)initUI { [self initTableViewAsDefaultStyle:_tableView]; } - (void)prepareViewDidLoad { [self requestPersonalNotices]; } #pragma mark - Main Logic - (void)requestPersonalNotices { //parameters NSDictionary *parameter = @{@"push_hist_id": _pagingId ? _pagingId : ksEmptyString, @"paging_type": _pagingType ? _pagingType : ksEmptyString}; NSString *path = API_GET_NOTICE_PERSONAL; [[RequestHandler handler] sendAsyncGetRequestAPIPath:path parameters:parameter modelClass:[PersonalNoticeListModel class] completion:^(id responseObject) { if (!responseObject) {//응답결과가 잘못되었거나 없을 경우, return; } PersonalNoticeListModel *fetchedPersonalNoticeList = (PersonalNoticeListModel *) responseObject; if (fetchedPersonalNoticeList && fetchedPersonalNoticeList.list && fetchedPersonalNoticeList.list.count) {//API 성공 , [_personalNoticeList addObjectsFromArray:fetchedPersonalNoticeList.list]; } else {//실패 시 } [_tableView reloadData]; } failure:^(id errorObject) { JDErrorModel *error = (JDErrorModel *)errorObject; [[JDFacade facade] alert:error.errorMessage]; }]; } #pragma mark - UITableView DataSource & Delegate - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return _personalNoticeList.count; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { CGFloat height = 160.0f; return height; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = nil; PersonalNoticeModel *notice = _personalNoticeList[indexPath.row]; if (notice) { MessageBoxTableViewCell *tcell = (MessageBoxTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"PersonalNoticeCellIdentifier"]; tcell.lblContent.text = notice.content; tcell.lblReadDatatime.text = notice.readDatetime; cell = tcell; } return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [super tableView:tableView didSelectRowAtIndexPath:indexPath]; } #pragma mark - UI Events - (IBAction)btnCloseTouched:(id)sender { [self dismissViewControllerAnimated:YES completion:nil]; } #pragma mark - MemoryWarning - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end