分享

PickerView常用方法

 叹落花 2015-01-30


// 与表视图相同,设置picker数据

@property(nonatomic,assign) id<UIPickerViewDataSource> dataSource;

// 与表视图相同,component(组件)宽度 以及行高度  设置picker外观 回调

@property(nonatomic,assign) id<UIPickerViewDelegate>   delegate;

// 显示一个picker视图当前指向的位置指示

@property(nonatomic)        BOOL                       showsSelectionIndicator;   // default is NO


// 一个picker视图有多少个组件

@property(nonatomic,readonly) NSInteger numberOfComponents;

// 一个组件有多少个行

- (NSInteger)numberOfRowsInComponent:(NSInteger)component;

// 返回picker视图其中一个组件的宽和高

- (CGSize)rowSizeForComponent:(NSInteger)component;

// 返回picker视图中自定义视图

- (UIView *)viewForRow:(NSInteger)row forComponent:(NSInteger)component;

// 重新加载所有组件内容

- (void)reloadAllComponents;

// 根据指定的组件,刷新组件中的数据

- (void)reloadComponent:(NSInteger)component;

// 制定picker视图的起始位置

- (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated;  // scrolls the specified row to center.

// 返回组件当前选中的行

- (NSInteger)selectedRowInComponent:(NSInteger)component;                                   // returns selected row. -1 if nothing selected


@end



@protocol UIPickerViewDataSource<NSObject>

@required


// 返回picker视图中有几个组件 类似与表视图数据源方法

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;


// 返回组件的行数

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;

@end



@protocol UIPickerViewDelegate<NSObject>

@optional


// 设置picker视图中 组件的宽度

- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component;

// 组件行的高度

- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component;


// 设置组件的内容

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;

// 自定义的时候需要调用这个方法

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view;


/*以上两个设置内容方法是相互的排斥*/


// 回调函数

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component;


//1.判断设备是否有前置摄像头. UIImagePickerControllerCameraDeviceRear 后置摄像头,还有一个是front是前置摄像头

    BOOL result = [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront];

    

    if (result) {


        UIImagePickerController *imgPickerCtrl = [[UIImagePickerController alloc] init];

        imgPickerCtrl.delegate = self;

        

        //源类型, 相机

        imgPickerCtrl.sourceType = UIImagePickerControllerSourceTypeCamera;

        //设置为前置摄像头

        imgPickerCtrl.cameraDevice = UIImagePickerControllerCameraDeviceFront;

        

        [self presentViewController:imgPickerCtrl animated:YES completion:^{

            

        }];

        

        [imgPickerCtrl release];

    }else{

        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:@"您的设备没有摄像头" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];

        [alertView show];

        [alertView release];

    }



----系统奇葩问题。保存图片

 UIImage *img = [UIImage imageWithData:data];

   

  //把图片保存到相册

  UIImageWriteToSavedPhotosAlbum(img, self, @selector(image:didFninishError:info:), NULL);


#pragma mark -

- (void)image:(UIImage *)image didFninishError:(NSError *)error info:(void *)contextInfo

{

    if (!error) {

        

        NSLog(@"保存图片成功");

    }

}





    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多