`

ios 工程代码整理

 
阅读更多
//  Query Message.h
//  Reservation software
//
//  Created by 张亚雄 on 15/7/7.
//  Copyright (c) 2015年 张亚雄. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface FindOrderTableViewController : UITableViewController<UITableViewDelegate,UITableViewDataSource>
{
    NSArray *m_arr_data_source;
    NSMutableArray *m_arr_data_sources;
    
}
@property(nonatomic,retain)UITableView *tableView;
@property(strong,nonatomic) NSArray *listData;

@end

 

//  Query Message.m

//  Reservation software

//

//  Created by 张亚雄 on 15/7/7.

//  Copyright (c) 2015张亚雄. All rights reserved.

//

 

#import "FindOrderTableViewController.h"

#import "ValueTableViewCell.h"

 

@interfaceFindOrderTableViewController ()

 

@end

 

@implementation FindOrderTableViewController

@synthesize listData=_listData;

 

 

- (void)viewDidLoad

{

    [superviewDidLoad];

     //    获取沙盒内的文件

    m_arr_data_source = [selfread_file_from_path:@"order.plist"];

    m_arr_data_sources = [selfread_file_from_path:@"nameFile.plist"];

    double sum_price = [selfget_ordered_sum_price];

    [selfcreat_label_price:sum_price];

    

}

-(double)get_ordered_sum_price

{

    //  for 循环如果i内容为1组,i行数为自动换行数

    for (int i = 0; i < m_arr_data_source.count; i++)

    {

        //   提取已定套餐内容

        NSDictionary *orderinfo = [m_arr_data_sourceobjectAtIndex:i];

        //        从已定套餐内容里提起name

        NSString *strName = [orderinfo objectForKey:@"name"];

        //      for循环变量j内容为1组,j行数为自动换行数

        for (int j = 0; j < m_arr_data_sources.count; j++)

        {

            //从未定套餐中名字中提取内容

            NSString *name = [m_arr_data_sourcesobjectAtIndex:j];

            //            对比strNamename的不同内容

            if ([strName isEqualToString:name])

            {

                //                减去相同的内容

                [m_arr_data_sourcesremoveObject:name];

                //                结束

                break;

            }

        }

    }

    double sum_price = 0;

    //    for循环提取k的自动行数

    for (int k = 0; k < m_arr_data_source.count; k++)

    {

        //    提取已定套餐显示的内容

        NSDictionary *priceinfo = [m_arr_data_sourceobjectAtIndex:k];

        //        从已定套餐内容提取想要显示的价位值转换字符串变数组

        NSString *strprice = [priceinfo objectForKey:@"price"];

        double double_price = strprice.doubleValue;

        sum_price = sum_price + double_price;

    }

    return sum_price;

}

-(UILabel *)creat_label_price:(double)sum_price

{

    //   声明一个lablesum_price 放到lable里。

    UILabel *label = [[UILabelalloc]initWithFrame:CGRectMake(0self.view.frame.size.height-73self.view.frame.size.width30)];

    label.backgroundColor = [UIColorblackColor];

    label.text = [[NSStringalloc]initWithFormat:@"总计%.2f",sum_price];

    label.font = [UIFontfontWithName:@"Arial"size:30];

    label.textAlignment = NSTextAlignmentCenter;

    label.textColor = [UIColorwhiteColor];

    label.adjustsFontSizeToFitWidth = YES;

    [self.viewaddSubview:label];

    return label;

}

 

//沙盒

- (NSMutableArray *)read_file_from_path:(NSString *)fileName

{

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectoryNSUserDomainMaskYES);

    //获取沙盒中Documents文件的路径

    NSString *str_file_path = [paths objectAtIndex:0];

    //将自己想创建的文件名添加到Documents录后,拼成一整个字符串

    NSString *str_data_file_path = [str_file_path stringByAppendingPathComponent:fileName];

    NSMutableArray *array_data_source = [[NSMutableArrayalloc]initWithContentsOfFile:str_data_file_path];

    return array_data_source;

    

}

- (void)didReceiveMemoryWarning

{

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

 

#pragma mark - Table view data source

/* 这个函数是显示tableview的章节数*/

-(NSInteger)numberOfSectionsInTableView:(UITableView*)tableView

{

    return2;

}

/*设置标题尾的宽度*/

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

{

    return30;

}

/*设置标题头的名称*/

 

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;

{

// 标题的   标头设置

    UIView *view = [[UIViewalloc]initWithFrame:CGRectMake(00self.view.frame.size.width30)];

    view.backgroundColor = [UIColorbrownColor];

    if (section == 0)

    {

        UILabel *label0ne =[[UILabelalloc]initWithFrame:CGRectMake(0,0,200,30)];

        label0ne.text = @"已定套餐";

        [view addSubview:label0ne];

    }

    else

    {

        UILabel *lableTwo = [[UILabelalloc]initWithFrame:CGRectMake(0020030)];

        lableTwo.text = @"未定套餐";

        [view addSubview:lableTwo];

    }

    return view;

}

 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

// 返回多少行

    if(section == 0)

    {

        returnm_arr_data_source.count;

    }

    if (section == 1)

    {

        returnm_arr_data_sources.count;

    }

    return0;

}

 

 

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    //    声明静态字符串型对象,用来标记重用单元格

    staticNSString *CellIdentifier = @"cells";

    //    TableSampleIdentifier表示需要重用的单元

    ValueTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    //    如果如果没有多余单元,则需要创建新的单元

    if (cell == nil)

    {

        cell = [[ValueTableViewCellallocinitWithStyle:UITableViewCellStyleDefaultreuseIdentifier:CellIdentifier];

    }

    if (indexPath.section == 0)

    {

        //    获取当前行信息值

        NSUInteger row = [indexPath row];

//        获取当价钱前值的行数

        NSString *str_price = [[m_arr_data_sourceobjectAtIndex:row]objectForKey:@"price"];

//        将价钱值类型转换成double类型,

        double d_price = str_price.doubleValue ;

//        将价钱值作比较大于11的数显示为红色。

        if (d_price > 11.00)

        {

            cell.price_text_label.textColor = [UIColorredColor];

        }

        //  name txte label = [[ sha he shu ju yuan zhong lei zhi yin ] yin yong zi dian nei ming cheng]

        cell.name_text_label.text = [[m_arr_data_sourceobjectAtIndex:row]objectForKey:@"name"];

        cell.price_text_label.text = str_price;

        cell.restaurant_text_label.text = [[m_arr_data_sourceobjectAtIndex:row]objectForKey:@"restaurant"];

        cell.combo_text_label.text = [[m_arr_data_sourceobjectAtIndex:row]objectForKey:@"combo"];

//        cell.money_text_label.text =[@"¥"];

    }

    if (indexPath.section == 1)

    {

        cell.textLabel.text = [m_arr_data_sourcesobjectAtIndex:indexPath.row];

    }

    return cell;

}

 

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

    return80;

}

 

 

@end

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics