7 Star 16 Fork 11

haiweihuiztech/MayStall-ios

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
CategoryDetailViewController.m 20.72 KB
一键复制 编辑 原始数据 按行查看 历史
Dawei Fan 提交于 2014-03-11 18:46 . submmit
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
//
// CategoryDetailViewController.m
// Maystall
//
// Created by Liqun on 27/02/2014.
// Copyright (c) 2014 huiztech. All rights reserved.
//
#import "CategoryDetailViewController.h"
#import "ProductViewController.h"
#import "ProductIDViewController.h"
#import "MayColorValue.h"
#import "MayValue.h"
#import "Config.h"
#import "UIImageView+WebCache.h"
#import "SBJson.h"
#import "ASIFormDataRequest.h"
#import <QuartzCore/QuartzCore.h>
#import "CheckNetwork.h"
#import "TMQuiltView.h"
#import "TMPhotoQuiltViewCell.h"
@interface CategoryDetailViewController ()
@end
@implementation CategoryDetailViewController
@synthesize name_CategoryDetail=name_CategoryDetail;
@synthesize ID_BtnTag=ID_BtnTag;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
LastestOrHotest=YES;
[self createNavigationBarItem];
[self createSecondaryTab];//创建下方最新最棒
[self getMainArray :@"lastest"];
// app = (MayAppDelegate *)[[UIApplication sharedApplication] delegate];
lastestBtn=[[NSMutableArray alloc]init];
hotestBtn=[[NSMutableArray alloc]init];
lastestBtn_height=[[NSMutableArray alloc]init];
hotestBtn_height=[[NSMutableArray alloc]init];
firstView=[[NSMutableArray alloc]init];
fisrstView_Height=[[NSMutableArray alloc]init];
}
- (void)viewWillAppear:(BOOL)animated
{
self.tabBarController.navigationController.navigationBarHidden = NO;
[self setTabNavigationBarTitleWithText:@"CategoryDetail"];//不好使
self.navigationItem.title =name_CategoryDetail;
self. navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:UITextAttributeTextColor];//更改导航栏标题颜色 为白色
qtmquitView = [[TMQuiltView alloc] initWithFrame:CGRectMake(0, 33 , 320, VIEW_HEIGHT)];
}
-(void)getMainArray :(NSString *)str
{
BOOL isNetWork=[CheckNetwork isExistenceNetwork];
[Config Instance].isNetworkRunning = [CheckNetwork isExistenceNetwork];
if(!isNetWork)//无网络
{
UIAlertView *alert =[[UIAlertView alloc] initWithTitle:@"提示"
message:@"网络不佳,请重新操作试试看~"
delegate:nil
cancelButtonTitle:nil
otherButtonTitles: @"确定",nil];
[alert show];
}
else
{
// http://www.maystall.com/index.php?route=mobile/ajax&action=products&path=64&debug=1
NSString *string=[NSString stringWithFormat:@"%@",kBASEURL];
NSURL *url = [ NSURL URLWithString : string ];
__weak ASIFormDataRequest *request = [ ASIFormDataRequest requestWithURL :url];
[request setRequestMethod:@"POST"];
[request setPostValue:kPRODCUTS forKey:kACTION];
[request setPostValue:ID_BtnTag forKey: kPATH];
[request setPostValue:str forKey:@"type"];
NSLog(@"%d",[request responseStatusCode]);
[request setCompletionBlock :^{
NSString * response = [request responseString];
SBJsonParser *parser = [[SBJsonParser alloc] init];
NSDictionary *array = [parser objectWithString:response];
// NSLog(@"%@",array);
[self creatWater:[array objectForKey:@"products" ] isLast:str];
// [self.view addSubview:qtmquitView];
//
}];
[request setFailedBlock :^{
// NSLog(@"HTTP 响应码:%d",[request responseStatusCode]);
// NSError *error = [request error ];
// NSLog ( @"error:%@" ,[error userInfo ]);
}];
[request startAsynchronous ];//异步
}
}
-(void)creatWater:(NSArray *)array isLast:(NSString *)str
{
NSMutableArray *View=[[NSMutableArray alloc]init];
NSMutableArray *View_Height=[[NSMutableArray alloc]init];
for(int i=0;i<array.count;i++)
{
NSDictionary *dict=[[NSDictionary alloc]init];
dict=[array objectAtIndex:i];
NSString *url=[NSString stringWithFormat:@"%@image/%@",webImageURL,[dict objectForKey:@"thumb"]] ;
UIImageView *imageView=[[UIImageView alloc]init];
// [imageView setImageWithURL:[NSURL URLWithString: url]];
// [app.arrary_height addObject:[NSString stringWithFormat:@"%f",imageView.image.size.height]];
[imageView setImageWithURL:[NSURL URLWithString: url]
placeholderImage:[UIImage imageNamed:@"moren.png"]
success:^(UIImage *image) {
[View addObject:[array objectAtIndex:i]];
[View_Height addObject:[NSString stringWithFormat:@"%f",image.size.height]];
if(View.count==array.count)
{
firstView=View;
fisrstView_Height=View_Height;
qtmquitView.delegate = self;
qtmquitView.dataSource = self;
[self.view addSubview:qtmquitView];
[qtmquitView reloadData];
[self createHeaderView];
[self performSelector:@selector(testFinishedLoadData) withObject:nil afterDelay:0.0f];
if([str isEqualToString:@"lastest"])
{
lastestBtn=View;
lastestBtn_height=View_Height;
}
else
{
hotestBtn=View;
hotestBtn_height=View_Height;
}
}
NSLog(@"图片显示成功OK " );}
failure:^(NSError *error) {
firstView=View;
fisrstView_Height=View_Height;
qtmquitView.delegate = self;
qtmquitView.dataSource = self;
[self.view addSubview:qtmquitView];
[qtmquitView reloadData];
[self createHeaderView];
[self performSelector:@selector(testFinishedLoadData) withObject:nil afterDelay:0.0f];
if([str isEqualToString:@"lastest"])
{
lastestBtn=View;
lastestBtn_height=View_Height;
}
else
{
hotestBtn=View;
hotestBtn_height=View_Height;
}
NSLog(@"图片显示失败NO");
}];
}
}
//================
//初始化刷新视图
//=================
#pragma mark
#pragma methods for creating and removing the header view
-(void)createHeaderView{
if (_refreshHeaderView && [_refreshHeaderView superview]) {
[_refreshHeaderView removeFromSuperview];
}
_refreshHeaderView = [[EGORefreshTableHeaderView alloc] initWithFrame:
CGRectMake(0.0f, 0.0f - self.view.bounds.size.height,
self.view.frame.size.width, self.view.bounds.size.height)];
_refreshHeaderView.delegate = self;
[qtmquitView addSubview:_refreshHeaderView];
[_refreshHeaderView refreshLastUpdatedDate];
}
-(void)testFinishedLoadData{
[self finishReloadingData];
[self setFooterView];
}
#pragma mark -
#pragma mark method that should be called when the refreshing is finished
- (void)finishReloadingData{
// model should call this when its done loading
_reloading = NO;
if (_refreshHeaderView) {
[_refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:qtmquitView];
}
if (_refreshFooterView) {
[_refreshFooterView egoRefreshScrollViewDataSourceDidFinishedLoading:qtmquitView];
[self setFooterView];
}
// overide, the actula reloading tableView operation and reseting position operation is done in the subclass
}
-(void)setFooterView{
// UIEdgeInsets test = self.aoView.contentInset;
// if the footerView is nil, then create it, reset the position of the footer
CGFloat height = MAX(qtmquitView.contentSize.height, qtmquitView.frame.size.height);
if (_refreshFooterView && [_refreshFooterView superview])
{
// reset position
_refreshFooterView.frame = CGRectMake(0.0f,
height,
qtmquitView.frame.size.width,
self.view.bounds.size.height);
}else
{
// create the footerView
_refreshFooterView = [[EGORefreshTableFooterView alloc] initWithFrame:
CGRectMake(0.0f, height,
qtmquitView.frame.size.width, self.view.bounds.size.height)];
_refreshFooterView.delegate = self;
[qtmquitView addSubview:_refreshFooterView];
}
if (_refreshFooterView)
{
[_refreshFooterView refreshLastUpdatedDate];
}
}
-(void)removeFooterView
{
if (_refreshFooterView && [_refreshFooterView superview])
{
[_refreshFooterView removeFromSuperview];
}
_refreshFooterView = nil;
}
//===============
//刷新delegate
#pragma mark -
#pragma mark data reloading methods that must be overide by the subclass
-(void)beginToReloadData:(EGORefreshPos)aRefreshPos{
// should be calling your tableviews data source model to reload
_reloading = YES;
if (aRefreshPos == EGORefreshHeader)
{
// pull down to refresh data
[self performSelector:@selector(refreshView) withObject:nil afterDelay:2.0];
}else if(aRefreshPos == EGORefreshFooter)
{
// pull up to load more data
[self performSelector:@selector(getNextPageView) withObject:nil afterDelay:2.0];
}
// overide, the actual loading data operation is done in the subclass
}
//刷新调用的方法
-(void)refreshView
{
NSLog(@"刷新完成");
[self testFinishedLoadData];
}
//加载调用的方法
-(void)getNextPageView
{
// for(int i = 0; i < 10; i++) {
// [_images addObject:[NSString stringWithFormat:@"%d.jpeg", i % 10 + 1]];
// }
//[qtmquitView reloadData];
if(LastestOrHotest)
{
firstView=lastestBtn;
fisrstView_Height=lastestBtn_height;
}
else
{
fisrstView_Height=hotestBtn_height;
firstView=hotestBtn;
}
[self removeFooterView];
[self testFinishedLoadData];
}
#pragma mark -
#pragma mark UIScrollViewDelegate Methods
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
if (_refreshHeaderView)
{
[_refreshHeaderView egoRefreshScrollViewDidScroll:scrollView];
}
if (_refreshFooterView)
{
[_refreshFooterView egoRefreshScrollViewDidScroll:scrollView];
}
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
if (_refreshHeaderView)
{
[_refreshHeaderView egoRefreshScrollViewDidEndDragging:scrollView];
}
if (_refreshFooterView)
{
[_refreshFooterView egoRefreshScrollViewDidEndDragging:scrollView];
}
}
#pragma mark -
#pragma mark EGORefreshTableDelegate Methods
- (void)egoRefreshTableDidTriggerRefresh:(EGORefreshPos)aRefreshPos
{
[self beginToReloadData:aRefreshPos];
}
- (BOOL)egoRefreshTableDataSourceIsLoading:(UIView*)view{
return _reloading; // should return if data source model is reloading
}
// if we don't realize this method, it won't display the refresh timestamp
- (NSDate*)egoRefreshTableDataSourceLastUpdated:(UIView*)view
{
return [NSDate date]; // should return date data source was last changed
}
//- (UIImage *)imageAtIndexPath:(NSIndexPath *)indexPath {
// return [UIImage imageNamed:[self.images objectAtIndex:indexPath.row]];
//}
- (NSInteger)quiltViewNumberOfCells:(TMQuiltView *)TMQuiltView {
return [fisrstView_Height count];
}
- (TMQuiltViewCell *)quiltView:(TMQuiltView *)quiltView cellAtIndexPath:(NSIndexPath *)indexPath {
TMPhotoQuiltViewCell *cell = (TMPhotoQuiltViewCell *)[quiltView dequeueReusableCellWithReuseIdentifier:@"PhotoCell"];
if (!cell) {
cell = [[TMPhotoQuiltViewCell alloc] initWithReuseIdentifier:@"PhotoCell"];
}
NSDictionary *dict=[[NSDictionary alloc]init];
dict=[firstView objectAtIndex:indexPath.row];
NSLog(@"======1");
NSString *url=[NSString stringWithFormat:@"%@image/%@",webImageURL,[dict objectForKey:@"thumb"]] ;
[cell.photoView setImageWithURL:[NSURL URLWithString: url]
placeholderImage:[UIImage imageNamed:@"moren.png"]
success:^(UIImage *image) { NSLog(@"======2"); NSLog(@"图片显示成功OK%d ",indexPath.row);}
failure:^(NSError *error) {NSLog(@"资讯置顶图片显示失败NO");}];
cell.titleLabel.text = [NSString stringWithFormat:@"%d", indexPath.row];
NSLog(@"======3");
UIView *back=[[UIView alloc]init];
back.backgroundColor=[UIColor whiteColor];
back.frame=CGRectMake(0, 0, 145.0, 80);
UILabel *label_name=[[UILabel alloc]initWithFrame:CGRectMake(4, 0, 136.0, 50)];
label_name.backgroundColor=[UIColor clearColor];
label_name.textColor=TAB_COLOR_DARK;
label_name.font=[UIFont fontWithName:@"Helvetica" size:13.0];
label_name.numberOfLines = 0;
label_name.lineBreakMode = NSLineBreakByTruncatingTail;//dkfd....
label_name.text=[dict objectForKey:@"name"];
[back addSubview:label_name];
UIImageView *price_ImageView=[[UIImageView alloc]initWithFrame:CGRectMake(-1, 49,82, 22)];
price_ImageView.image=[UIImage imageNamed:@"price_Label.png"];
UILabel *price_label=[[UILabel alloc]initWithFrame:CGRectMake(20,2, 59, 17)];
price_label.textColor=TAB_COLOR_LIGHT;
price_label.backgroundColor=[UIColor clearColor];
NSString *price_str=[dict objectForKey:@"price"];
NSString *special=[NSString stringWithFormat:@"%@",[dict objectForKey:@"special"]];
if([special isEqualToString:@"0"])
{
price_label.text=price_str;
}
else
{
price_label.text=special;
}
price_label.font=[UIFont fontWithName:@"Helvetica" size:12.0];
[price_ImageView addSubview:price_label];
[back addSubview:price_ImageView];
UIImageView *love_imageView=[[UIImageView alloc]initWithFrame:CGRectMake(95, 52, 20, 17)];
love_imageView.image=[UIImage imageNamed:@"icon_product_favorite_normal.png"];
[back addSubview:love_imageView];
UILabel *love_total=[[UILabel alloc]initWithFrame:CGRectMake(116, 52, 28, 17)];
love_total.backgroundColor=[UIColor clearColor];
love_total.textColor=TAB_COLOR_LIGHT;
love_total.font=[UIFont fontWithName:@"Helvetica" size:12.0];
love_total.text=[dict objectForKey:@"liked"];
[back addSubview:love_total];
NSLog(@"======4");
[cell.view addSubview:back]; return cell;
}
#pragma mark - TMQuiltViewDelegate
- (NSInteger)quiltViewNumberOfColumns:(TMQuiltView *)quiltView {
return 2;
}
- (CGFloat)quiltView:(TMQuiltView *)quiltView heightForCellAtIndexPath:(NSIndexPath *)indexPath
{
return [[fisrstView_Height objectAtIndex:indexPath.row]integerValue] / [self quiltViewNumberOfColumns:quiltView];
}
- (void)quiltView:(TMQuiltView *)quiltView didSelectCellAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary *dict=[[NSDictionary alloc]init];
dict=[firstView objectAtIndex:indexPath.row];
// NSLog(@"====ID:%@",[dict objectForKey:@"product_id"]);
// ProductViewController *view=[[ProductViewController alloc] init];
// [self.navigationController pushViewController:view animated:YES];
// [self dismissViewControllerAnimated:YES completion:nil];
ProductIDViewController *view=[[ProductIDViewController alloc] init];
view.ID_Product=[dict objectForKey:@"product_id"];
view.Name_Product=[dict objectForKey:@"name"];
[self.navigationController pushViewController:view animated:YES];
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)createNavigationBarItem
{
//左键
UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
leftButton.frame = CGRectMake(0, 0, 60, 31);
[leftButton setTitle:@"Back" forState:UIControlStateNormal];
[leftButton.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:13]];
[leftButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[leftButton addTarget:self action:@selector(backToPreviousView) forControlEvents:UIControlEventTouchUpInside];
[leftButton setBackgroundImage:[UIImage imageNamed:@"btn_nav_back"] forState:UIControlStateNormal];
UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] init];
[leftItem setCustomView:leftButton];
self.navigationItem.leftBarButtonItem = leftItem;
//右键
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
rightButton.frame = CGRectMake(0, 0, 40, 31);
[rightButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[rightButton addTarget:self action:@selector(backToPreviousView) forControlEvents:UIControlEventTouchUpInside];
[rightButton setBackgroundImage:[UIImage imageNamed:@"btn_nav_home"] forState:UIControlStateNormal];
UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] init];
[rightItem setCustomView:rightButton];
self.navigationItem.rightBarButtonItem = rightItem;
}
-(void)createSecondaryTab//Home页面 最新 最好 的两个选择按钮
{
UIView *secondaryTabView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 33)];
secondaryTabView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg_btn_wave"]];
CGSize titleSize = [@"Bestseller" sizeWithFont:[UIFont fontWithName:@"Helvetica" size:12.0]];
_newestBtn = [[UIButton alloc] init];
_newestBtn.titleLabel.Font = [UIFont fontWithName:@"Helvetica" size:12.0];
_newestBtn.frame = CGRectMake(40, 6, titleSize.width += 10, 21);
_newestBtn.tag=100;
[_newestBtn setBackgroundImage:[UIImage imageNamed:@"btn_wave_selected"] forState:UIControlStateSelected];
[_newestBtn setTitleColor:TAB_COLOR_DARK forState:UIControlStateNormal];
[_newestBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
[_newestBtn setTitle:@"Newest" forState:UIControlStateNormal];
[_newestBtn addTarget:self action:@selector(BtnSelected:) forControlEvents:UIControlEventTouchUpInside];
_newestBtn.selected = YES;
_bestSellerBtn = [[UIButton alloc] init];
int marginRight = 320-40-titleSize.width-10;
_bestSellerBtn.tag=200;
_bestSellerBtn.titleLabel.Font = [UIFont fontWithName:@"Helvetica" size:12.0];
_bestSellerBtn.frame = CGRectMake(marginRight, 6, titleSize.width += 10, 21);
[_bestSellerBtn setBackgroundImage:[UIImage imageNamed:@"btn_wave_selected"] forState:UIControlStateSelected];
[_bestSellerBtn setTitleColor:TAB_COLOR_DARK forState:UIControlStateNormal];
[_bestSellerBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
[_bestSellerBtn setTitle:@"Bestseller" forState:UIControlStateNormal];
[_bestSellerBtn addTarget:self action:@selector(BtnSelected:) forControlEvents:UIControlEventTouchUpInside];
[secondaryTabView addSubview:_newestBtn];
[secondaryTabView addSubview:_bestSellerBtn];
[self.view addSubview:secondaryTabView];
}
#pragma -mark button action
- (void)BtnSelected:(id)sender
{
UIButton *btn=(UIButton *)sender;
[fisrstView_Height removeAllObjects];
[firstView removeAllObjects];
if(btn.tag==100)
{
LastestOrHotest=YES;
_newestBtn.selected = YES;
_bestSellerBtn.selected = NO;
[self getMainArray :@"lastest"];
}
else
{
LastestOrHotest=NO;
_newestBtn.selected = NO;
_bestSellerBtn.selected = YES;
[self getMainArray :@"hot"];
}
qtmquitView.delegate = self;
qtmquitView.dataSource = self;
[self.view addSubview:qtmquitView];
[qtmquitView reloadData];
}
- (void)backToPreviousView
{
[self.navigationController popViewControllerAnimated:YES];
}
@end
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Objective-C
1
https://gitee.com/haiweihuiztech/MayStall-ios.git
git@gitee.com:haiweihuiztech/MayStall-ios.git
haiweihuiztech
MayStall-ios
MayStall-ios
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385