211 lines
6.4 KiB
Objective-C
211 lines
6.4 KiB
Objective-C
//
|
|
// GiGaFeedBackKindView.m
|
|
// GIGA
|
|
//
|
|
// Created by lianxiang on 2018/9/23.
|
|
// Copyright © 2018年 com.giga.ios. All rights reserved.
|
|
//
|
|
|
|
#import "GiGaFeedBackKindView.h"
|
|
#define PickerHeight 180
|
|
#define PickerToolBarHeight 44
|
|
#import "GiGaBaseAPiRequest.h"
|
|
#import "GIGaFeedKind.h"
|
|
|
|
@interface GiGaFeedBackKindView ()<UIPickerViewDelegate,UIPickerViewDataSource>
|
|
|
|
@property (nonatomic, strong) UIView *pickerContainerView;
|
|
@property (nonatomic, strong) UIPickerView *pickerView;
|
|
//picker控件数据源
|
|
@property(nonatomic,strong)NSMutableArray *pickerDataArr;
|
|
|
|
@end
|
|
|
|
@implementation GiGaFeedBackKindView
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
self.view.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.4];
|
|
self.pickerDataArr = [NSMutableArray new];
|
|
[self initUI];
|
|
// Do any additional setup after loading the view.
|
|
|
|
}
|
|
|
|
-(void)requstData{
|
|
GiGaBaseAPiRequest *api = [GiGaBaseAPiRequest initWithRequestPath:kApiGetFeedList method:RequestPostMethod parms:@{}];
|
|
[api requstDataWithResult:^(GiGaAPIResult *result) {
|
|
if (result.success) {
|
|
GILog(@"反馈类型%@",result.dic);
|
|
NSArray *list =result.dic[@"list"];
|
|
if (!list) {
|
|
list= [NSArray new];
|
|
}
|
|
for (NSDictionary *feedDic in list) {
|
|
GIGaFeedKind *mode = [[GIGaFeedKind alloc] initWithDictionary:feedDic error:nil];;
|
|
[self.pickerDataArr addObject:mode];
|
|
}
|
|
|
|
[self.pickerView reloadAllComponents];
|
|
[self.pickerView selectRow:self.defultRow inComponent:0 animated:YES];
|
|
GIGaFeedKind *mode = self.pickerDataArr[self.defultRow];
|
|
if (mode) {
|
|
self.showKind =mode;
|
|
}
|
|
|
|
}else{
|
|
|
|
GIGA_ShowToast(result.message);
|
|
}
|
|
}];
|
|
}
|
|
|
|
-(void)initUI{
|
|
|
|
self.pickerContainerView = [[UIView alloc] initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height - (PickerHeight + PickerToolBarHeight), [UIScreen mainScreen].bounds.size.width, PickerHeight + PickerToolBarHeight)];
|
|
|
|
UIToolbar *toolBar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, PickerToolBarHeight)];
|
|
toolBar.barTintColor = [UIColor whiteColor];
|
|
|
|
UIBarButtonItem *noSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
|
|
noSpace.width=10;
|
|
|
|
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithTitle:@"确定" style:UIBarButtonItemStylePlain target:self action:@selector(done:)];;
|
|
doneBtn.tintColor = GIGARGB(131, 10, 10, 1);
|
|
|
|
UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(cancel:)];
|
|
cancelBtn.tintColor = GIGARGB(131, 10, 10, 1);
|
|
|
|
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
|
|
[toolBar setItems:[NSArray arrayWithObjects:noSpace,cancelBtn,flexSpace,doneBtn,noSpace, nil]];
|
|
UILabel *titleLabel = [UILabel new];
|
|
titleLabel.frame = CGRectMake(0, 0, 200, PickerToolBarHeight);
|
|
titleLabel.center = toolBar.center;
|
|
titleLabel.textAlignment = NSTextAlignmentCenter;
|
|
titleLabel.textColor = GIGARGB(62, 62, 62, 1);
|
|
titleLabel.text = @"反馈类型";
|
|
titleLabel.font = GIGA_TEXTFONTBOLD(14);
|
|
[toolBar addSubview:titleLabel];
|
|
|
|
self.pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, PickerToolBarHeight, [UIScreen mainScreen].bounds.size.width, PickerHeight)];
|
|
self.pickerView.dataSource = self;
|
|
self.pickerView.delegate = self;
|
|
self.pickerView.backgroundColor = [UIColor whiteColor];
|
|
|
|
[self.pickerContainerView addSubview:toolBar];
|
|
[self.pickerContainerView addSubview:self.pickerView];
|
|
[self.view addSubview:self.pickerContainerView];
|
|
|
|
}
|
|
|
|
|
|
#pragma mark-- UIPickerViewDataSource
|
|
//列数
|
|
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
//每列个数
|
|
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
|
|
{
|
|
return [self.pickerDataArr count];
|
|
}
|
|
|
|
|
|
#pragma mark-- UIPickerViewDelegate
|
|
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
|
|
{
|
|
UILabel *label = (id)view;
|
|
if (!label)
|
|
{
|
|
label= [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, [pickerView rowSizeForComponent:component].width, [pickerView rowSizeForComponent:component].height)];
|
|
label.textAlignment = NSTextAlignmentCenter;
|
|
label.textColor = [UIColor blackColor];
|
|
GIGaFeedKind *mode = self.pickerDataArr[row];
|
|
label.text = mode.dictLabel;
|
|
}
|
|
return label;
|
|
}
|
|
|
|
//点击选择
|
|
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
|
|
{
|
|
if (self.selectedItemBlock) {
|
|
|
|
if (self.pickerDataArr.count > 0 ) {
|
|
GIGaFeedKind *mode = self.pickerDataArr[row];
|
|
self.showKind = mode;
|
|
self.selectedItemBlock(mode);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
-(void)done:(UIButton *)btn{
|
|
|
|
if (self.selectedItemBlock) {
|
|
if ([self.showKind.dictLabel isEqualToString:@"未知"]) {
|
|
[self hide];
|
|
return;
|
|
}
|
|
|
|
self.selectedItemBlock(self.showKind);
|
|
|
|
}
|
|
|
|
[self hide];
|
|
|
|
}
|
|
|
|
-(void)cancel:(UIButton*)btn{
|
|
|
|
[self hide];
|
|
|
|
}
|
|
|
|
-(void)hide{
|
|
|
|
[self dismissViewControllerAnimated:NO completion:^{
|
|
|
|
}];
|
|
}
|
|
|
|
+(GiGaFeedBackKindView *)showAt:(UIViewController *)vc atRow:(NSInteger)row
|
|
{
|
|
|
|
GiGaFeedBackKindView *piker = [[GiGaFeedBackKindView alloc] init];
|
|
if (!row) {
|
|
row = 0;
|
|
}
|
|
piker.defultRow = row;
|
|
[vc presentViewController:piker animated:YES completion:^{
|
|
|
|
}];
|
|
|
|
return piker;
|
|
}
|
|
|
|
-(instancetype)init{
|
|
|
|
if (self = [super init]) {
|
|
self.modalPresentationStyle = UIModalPresentationOverCurrentContext;
|
|
|
|
self.showKind = [[GIGaFeedKind alloc] init];
|
|
self.showKind.dictLabel = @"未知";
|
|
|
|
[self requstData];
|
|
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)didReceiveMemoryWarning {
|
|
[super didReceiveMemoryWarning];
|
|
// Dispose of any resources that can be recreated.
|
|
}
|
|
|
|
|
|
|
|
@end
|