加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
MessageViewController.m 6.76 KB
一键复制 编辑 原始数据 按行查看 历史
xiexiaolong.xxl 提交于 2024-06-18 15:06 . init
//
// 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
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化