代码拉取完成,页面将自动刷新
//
// MessageViewController.m
// officeMobile
//
// Created by Points on 15-3-5.
// Copyright (c) 2015年 com.kinggrid. All rights reserved.
//
#import "MessageViewController.h"
#import "SendMsgTableViewCell.h"
#import "MessageDetailViewController.h"
#import "SendMessageViewController.h"
@interface MessageViewController ()<UITableViewDataSource,UITableViewDelegate>
@end
@implementation MessageViewController
-(id)init
{
if(self = [super initWithStyle:UITableViewStylePlain withIsNeedPullDown:YES withIsNeedPullUpLoadMore:YES withIsNeedBottobBar:YES])
{
self.tableView.dataSource = self;
self.tableView.delegate = self;
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
m_searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, MAIN_WIDTH, HEIGHT_NAVIGATION)];
[m_searchBar setDelegate:self];
[m_searchBar setPlaceholder:@"请输入查询关键字"];
m_searchBar.showsCancelButton = YES;
self.tableView.tableHeaderView = m_searchBar;
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self removeBackBtn];
[title setText:@"我的消息"];
UIButton *slideBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[slideBtn addTarget:self action:@selector(backBtnClicked) forControlEvents:UIControlEventTouchUpInside];
[slideBtn setFrame:CGRectMake(10,4+DISTANCE_TOP, 32, 34)];
[slideBtn setBackgroundImage:[UIImage imageNamed:@"home_more"] forState:UIControlStateNormal];
[navigationBG addSubview:slideBtn];
[self createButtons];
}
- (void)createButtons
{
self.m_currentIndex = 0;
self.m_arrCategory = @[@"短信列表",@"发送短信"];
NSMutableArray *arr = [NSMutableArray array];
for(int i =0 ;i<self.m_arrCategory.count;i++)
{
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn addTarget:self action:@selector(categoryBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
btn.tag = i;
[btn setFrame:CGRectMake(i*(MAIN_WIDTH/self.m_arrCategory.count), CGRectGetMaxY(navigationBG.frame), MAIN_WIDTH/self.m_arrCategory.count, 40)];
[btn setTitle:[self.m_arrCategory objectAtIndex:i] forState:UIControlStateNormal];
[btn setTitleColor:i == 0 ? KEY_COMMON_CORLOR : [UIColor grayColor] forState:UIControlStateNormal];
[self.view addSubview:btn];
[arr addObject:btn];
}
self.m_arrBtn = arr;
m_tipView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(navigationBG.frame)+36, MAIN_WIDTH/self.m_arrCategory.count, 4)];
[self.view addSubview:m_tipView];
[m_tipView setBackgroundColor:KEY_COMMON_CORLOR];
[self.tableView setFrame:CGRectMake(0, CGRectGetMaxY(m_tipView.frame), MAIN_WIDTH,MAIN_HEIGHT-CGRectGetMaxY(m_tipView.frame)-HEIGHT_MAIN_BOTTOM)];
}
#pragma mark - private
- (void)categoryBtnClicked:(UIButton *)btn
{
self.m_currentIndex = btn.tag;
if(self.m_currentIndex == 0)
{
[self requestData:YES];
}
else
{
SendMessageViewController *info = [[SendMessageViewController alloc]init];
info.m_delegate = self;
[self.navigationController pushViewController:info animated:YES];
return;
}
for(UIButton *button in self.m_arrBtn)
{
if(button.tag == btn.tag)
{
[button setTitleColor:KEY_COMMON_CORLOR forState:UIControlStateNormal];
}
else
{
[button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
}
}
[UIView animateWithDuration:0.3 animations:^{
[m_tipView setFrame:CGRectMake(self.m_currentIndex*(MAIN_WIDTH/self.m_arrCategory.count), m_tipView.frame.origin.y, m_tipView.frame.size.width, m_tipView.frame.size.height)];
}];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma MARK -
- (void)requestData:(BOOL)isRefresh
{
[self showWaitingView];
self.m_isRefresh = isRefresh;
if(isRefresh)
{
self.m_arrData = nil;
}
[HTTP_MANAGER getMessageWithTel:nil
WithKey:m_searchBar.text
startIndex:[NSNumber numberWithInteger:self.m_arrData.count]
successedBlock:^(NSDictionary *retDic){
[self processData:retDic];
} failedBolck:FAILED_BLOCK{
[self reloadDeals];
}];
}
- (void)processData:(NSDictionary *)retDic
{
if(self.m_isRefresh)
{
NSDictionary *ret = [retDic[@"DATA"] mutableObjectFromJSONString];
self.m_arrData = ret[@"result"];
}
else
{
NSDictionary *ret = [retDic[@"DATA"] mutableObjectFromJSONString];
NSArray *arrRet = ret[@"result"];
NSMutableArray *arr = [NSMutableArray arrayWithArray:self.m_arrData];
[arr addObjectsFromArray:arrRet];
self.m_arrData = arr;
}
[self reloadDeals];
}
#pragma mark - TableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 60;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.m_arrData.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * identify = @"spe";
SendMsgTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identify];
if(cell == nil)
{
cell = [[SendMsgTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identify];
}
cell.currentDic = [self.m_arrData objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
MessageDetailViewController *info = [[MessageDetailViewController alloc]initWithInfo:[self.m_arrData objectAtIndex:indexPath.row]];
info.m_delegate = self;
[self.navigationController pushViewController:info animated:YES];
}
#pragma mark - 侧滑栏操作
- (void)backBtnClicked
{
[self.m_delegate onShowSliderView];
}
#pragma mark - UISearchBarDelegate
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
[searchBar resignFirstResponder];
[self requestData:self.m_isRefresh];
}
- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar
{
[searchBar resignFirstResponder];
return YES;
}
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
{
searchBar.text = nil;
[searchBar resignFirstResponder];
[self requestData:self.m_isRefresh];
}
- (void)onNeedRefreshTableView
{
[self requestData:YES];
}
@end
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。