糯米团—重制“iPhone团购信息客户端”(二)

好,接着上一篇来,BusinessLogicLayer完了之后是PresentationLayer

PresentationLayer

首先从MainCell文件夹里开始
这里面存放的是GridView的单元格的定义,最终呈现出
cell
的样式。

GridViewCell.h

#import "AQGridViewCell.h"

@interface GridViewCell : AQGridViewCell

@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UILabel *captionLabel;
@property (nonatomic, strong) UILabel *priceLabel;
@property (nonatomic, strong) UIButton *imageButton;

@end

GridViewCell.m

#import "GridViewCell.h"
#import <QuartzCore/QuartzCore.h>

@implementation GridViewCell

- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier];
    if (self) {
        //初始化cell
        UIView *mainView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 187.5, 175)];
        //背景无色
        [mainView setBackgroundColor:[UIColor clearColor]];
        //图片框架
        UIImageView *frameImageView = [[UIImageView alloc] initWithFrame:CGRectMake(23, 4, 142, 163)];
        [frameImageView setImage:[UIImage imageNamed:@"tab-mask.png"]];
        [mainView addSubview:frameImageView];
        //图片和标题属性
        self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(26, 42, 135, 84)];
        self.captionLabel = [[UILabel alloc] initWithFrame:CGRectMake(26, 4, 136, 36)];
        [_captionLabel setFont:[UIFont systemFontOfSize:12]];
        _captionLabel.numberOfLines = 2;
        [mainView addSubview:_imageView];
        [mainView addSubview:_captionLabel];
        //价格
        _priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(28, 128, 70, 30)];
        _priceLabel.font = [UIFont boldSystemFontOfSize:16];
        _priceLabel.textColor = [UIColor orangeColor];
        [mainView addSubview:_priceLabel];
        //底部按钮
        _imageButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _imageButton.frame = CGRectMake(98, 131, 60, 22);
        [_imageButton setBackgroundImage:[UIImage imageNamed:@"goToMap.jpg"] forState:UIControlStateNormal];
        //如果想底层view和imageButton相接洽,或者类似于融合了视图,就设置为NO。这样设置YES底层视图和button执行的操作可以互不干扰,当然默认是YES的,kangkangz4 添加了看似多余的按钮真的给了我一个很好的启发 :)
        _imageButton.userInteractionEnabled = YES;
        [mainView addSubview:_imageButton];

        [self.contentView addSubview:mainView];
    }
    return self;
}

@end

单元格属性处理完毕之后就是弹出城市选单 的 设置。

popover

PopTableViewController.h

#import <UIKit/UIKit.h>

@interface PopTableViewController : UITableViewController

@property (nonatomic, strong) NSString *city;

@end

PopTableViewController.m

#import "PopTableViewController.h"

@interface PopTableViewController ()

@property (nonatomic, strong) NSArray *cities;

@end

@implementation PopTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _cities = [[NSArray alloc] initWithObjects:@"南京", @"澳门", @"香港", nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellIdentify = @"Cell";
    //这种写cell的方式就不能后跟 forIndexPath 了
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentify];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentify];
    }
    cell.textLabel.text = _cities[indexPath.row];

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    _city = _cities[indexPath.row];
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"PopoverDismiss" object:nil];
}

@end
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值