当前位置:  编程技术>移动开发
本页文章导读:
    ▪构建SEL RUNTIME调用步骤        构建SEL RUNTIME调用方法         for (int i = 1; i< 3; i++) {        SEL customSelector = NSSelectorFromString([NSString stringWithFormat:@"update%d", i]);        if ([self respondsToSelector:customSelector]) {      .........
    ▪ 异步读取raw文件上大文件的内容        异步读取raw文件下大文件的内容 AsyncTask,异步处理,主要用于将比较耗时的操作从主线程(UI线程)中分离出来处理,提高运行速度(流畅度)。本来是要学习AsyncTask的,当看到耗时操作.........
    ▪ 自定义pickview以及选中成效       自定义pickview以及选中效果 // // ViewController.m // UIPickerViewBySelf // // Created by MAC on 13-1-29. // Copyright (c) 2013年 MAC. All rights reserved. // #import "ViewController.h" @interface ViewController () @end @implementati.........

[1]构建SEL RUNTIME调用步骤
    来源: 互联网  发布时间: 2014-02-18
构建SEL RUNTIME调用方法

 

 

    for (int i = 1; i< 3; i++) {
        SEL customSelector = NSSelectorFromString([NSString stringWithFormat:@"update%d", i]);
        if ([self respondsToSelector:customSelector]) {
             [self performSelector:customSelector];
        }
    }


    
[2] 异步读取raw文件上大文件的内容
    来源: 互联网  发布时间: 2014-02-18
异步读取raw文件下大文件的内容
AsyncTask,异步处理,主要用于将比较耗时的操作从主线程(UI线程)中分离出来处理,提高运行速度(流畅度)。本来是要学习AsyncTask的,当看到耗时操作时就考虑到了读取大文件操作,然后自己试着读取raw文件夹下面的文件。
有两种方式读取,一种是按行读取,一种是按大小读取;
主要代码如下:
一:按行读取
关键代码:
class FileReadTask extends AsyncTask<String, String, String> {
                String line_str;
                String result;
                Context context;

                FileReadTask(Context context) {
                        this.context = context;
                }
                int i = 0;
                @Override
                protected String doInBackground(String... params) {
                        BufferedReader reader = new BufferedReader(new InputStreamReader(
                                        context.getResources().openRawResource(R.raw.test2)));
                        try {
                                while ((line_str = reader.readLine()) != null
                                                && !(line_str = reader.readLine()).equals("")) {
                                        result += line_str;
                                        System.out.println("line_str:"+line_str);
                                        publishProgress(line_str);
                                }
                                System.out.println("result:"+result);
                        } catch (IOException e) {
                                e.printStackTrace();
                        }
                        return line_str;
                }

                @Override
                protected void onPostExecute(String result) {
                        super.onPostExecute(result);

                }

                @Override
                protected void onPreExecute() {
                        super.onPreExecute();

                }

                @Override
                protected void onProgressUpdate(String... values) {
                        super.onProgressUpdate(values[0]);
                        System.out.println("values:" + values[0]);
                        array.add(values[0]);
                        adapter.notifyDataSetChanged();
                }

        }


二:按大小读取
关键代码:
InputStream input = context.getResources().openRawResource(R.raw.test2);
                String result = null;
                int i;
                byte[] by = new byte[128];//每次读取大小
                try {
                        while((i = input.read(by))>0){
                                byte[] bys = new byte[i];
                                input.read(bys,0,i);
                                String s = new String(bys);
                                result +=s;
                                System.out.println(s);
                        }
                } catch (IOException e) {
                        e.printStackTrace();
                }

    
[3] 自定义pickview以及选中成效
    来源: 互联网  发布时间: 2014-02-18
自定义pickview以及选中效果
//
//  ViewController.m
//  UIPickerViewBySelf
//
//  Created by MAC on 13-1-29.
//  Copyright (c) 2013年 MAC. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize fontlabel;
@synthesize pickView;
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.pickView.dataSource = self;
    self.pickView.delegate = self;
    
    fonts = [UIFont familyNames];
    fontSize = [NSArray arrayWithObjects:@"10",@"15",
                                          @"20",@"25",
                                          @"30",@"35",
                 @"40",@"45", nil];
    
    fontColor =[NSArray arrayWithObjects:
                [UIColor redColor],
                [UIColor blueColor],
                [UIColor blackColor],
                [UIColor yellowColor],
                [UIColor grayColor],
                [UIColor greenColor],
                [UIColor brownColor],
                [UIColor orangeColor],
                [UIColor purpleColor],
                [UIColor magentaColor],nil];
    
    for(int i= 0;i<3;i++)
    {
        int row = 0;
        if(i==0)
        {
            row = [fonts count]/2;
        }
        else if (i==1)
        {
            row = [fontColor count]/2;
        }
        else if (i==2)
        {
            row =[fontSize count]/2;
        }
[pickView selectRow:row inComponent:i animated:true];
    }


//    [fontColor retain];
    
	// Do any additional setup after loading the view, typically from a nib.
}
-(void) pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    UIView *view0,*view1,*view2;
    NSInteger row0,row1,row2;
    row0 = [pickView selectedRowInComponent:0];
    row1 = [pickView selectedRowInComponent:1];
    row2 = [pickView selectedRowInComponent:2];
    
    view0 = [pickView viewForRow:row0 forComponent:0];
    view1 = [pickView viewForRow:row1 forComponent:1];
    view2 = [pickView viewForRow:row2 forComponent:2];
    


    UILabel *label1,*label2,*label0;
    label0 =(UILabel *)[view0 viewWithTag:200];
    label1 =(UILabel *)[view1 viewWithTag:200];
    label2 =(UILabel *)[view2 viewWithTag:200];
    
    fontlabel.font = [UIFont fontWithName:label0.text size:[label2.text floatValue]];
    fontlabel.textColor = label1.backgroundColor;
}

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

#pragma mark -
#pragma mark UIPICKVIEW CUSTOM FUNTION
//返回一共几列的值
-(NSInteger) numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 3;
}
//返回每列具体多少行
-(NSInteger) pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    if(component==0)
    {
        return [fonts count];}
    else if(component==1)
    {
        return [fontColor count];
        
    }
    else if(component ==2)
    {
        return [fontSize count];
    }
    return -1;
}
//返回三列各列宽度
-(CGFloat) pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component
{
    if(component==0)
    {
        return 180.0f;}
    else if(component==1)
    {
        return 90.0f;
        
    }
    else if(component ==2)
    {
        return 50.0f;
    }
    return 0.0f;
}
//返回row高度
-(CGFloat) pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
{
    return 50.0f;
}
//可以理解为自定义的view内容
-(UIView *) pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
    CGFloat width = [self pickerView:pickView widthForComponent:component];
    CGFloat rowheight =[self pickerView:pickView rowHeightForComponent:(component)];
    
    UIView *myView = [[UIView alloc]init];
    myView.frame =CGRectMake(0.0f, 0.0f, width, rowheight);
    UILabel *txtlabel = [[UILabel alloc] init];
    txtlabel.tag=200;
    txtlabel.frame = myView.frame;
    
    [myView addSubview:txtlabel];
    if(component==0)
    {
        txtlabel.text = [fonts objectAtIndex:row];
    }
    else if(component==1)
    {
        txtlabel.backgroundColor =[fontColor objectAtIndex:row];
    }
    else if(component==2)
    {
        txtlabel.text =[fontSize objectAtIndex:row];
    }
    return myView;
}


@end


    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3