我尝试将5张图片上传到服务器,并且有5个按钮和5个[RACObserve(self, keyboardType) subscribeNext:^(NSNumber *keyboardType) {
NSLog(@"%ld", (long)keyboardType.integerValue);
// Or any other user of keyboardType.integerValue, such as:
if (keyboardType.integerValue == UIKeyboardTypeURL) {
// Do stuff.
}
}];
。如果单击第一个按钮,则应该获取第一个ImageView图像,并且与所有按钮一样,应选择表示ImageView
。但是问题是,如果我单击第一个按钮或任何按钮,然后从图库中选择图像,第五个ImageView
仅获得图像。
ImageView
答案 0 :(得分:0)
i declared five flags for five button.and i gave tag for each button.
var flag1 = 0
var flag2 = 0
var flag3 = 0
var flag4 = 0
var flag5 = 0
我针对五个按钮给出了五个目标动作
addAttachBtn1.addTarget(self,action: #selector(selectFirstImage), for: .touchUpInside)
addAttach2.addTarget(self,action: #selector(selectSecondImage), for: .touchUpInside)
addAttach3.addTarget(self,action: #selector(selectThirdImage), for: .touchUpInside)
addAttach4.addTarget(self,action: #selector(selectFourthImage), for: .touchUpInside)
addAttach5.addTarget(self,action: #selector(selectFifthImage), for: .touchUpInside)
@objc func selectFirstImage(sender: UIButton){
addAttachBtn1.tag = 1
flag1 = 1
alertControllerPOPupView()
addAttachBtn1.titleLabel?.text = str_Url_name
}
@objc func selectSecondImage(sender: UIButton){
addAttach2.tag = 2
flag2 = 2
alertControllerPOPupView()
addAttach2.titleLabel?.text = str_Url_name
}
@objc func selectThirdImage(sender: UIButton){
addAttach3.tag = 1
flag3 = 1
alertControllerPOPupView()
addAttach2.titleLabel?.text = str_Url_name
}
@objc func selectFourthImage(sender: UIButton){
addAttach4.tag = 1
flag4 = 1
alertControllerPOPupView()
}
@objc func selectFifthImage(sender: UIButton){
flag5 = 1
addAttach5.tag = 1
alertControllerPOPupView()
}
之后,我宣布从Gallery进行imagePicking和videoPicking的alertController
func alertControllerPOPupView(){
let aletcontroller:UIAlertController = {
let alert = UIAlertController(title: "Choose Pic From..", message: "please select the picture source", preferredStyle: .actionSheet)
let camera = UIAlertAction(title: "Camera", style: .default, handler: { (cameraAction) in
if UIImagePickerController.isSourceTypeAvailable(.camera){
let cameraPicker = UIImagePickerController.init()
cameraPicker.delegate = self
cameraPicker.sourceType = .camera
cameraPicker.allowsEditing = false
self.present(cameraPicker, animated: true, completion: nil)
}
})
let saveAlbum = UIAlertAction(title: "Picture", style: .default, handler: { (galleryAction) in
if UIImagePickerController.isSourceTypeAvailable(.photoLibrary){
let cameraPicker = UIImagePickerController.init()
cameraPicker.delegate = self
cameraPicker.sourceType = .photoLibrary
cameraPicker.allowsEditing = false
self.present(cameraPicker, animated: true, completion: nil)
}
})
let VideoAlbm = UIAlertAction(title: "Video", style: .default, handler: { (galleryAction) in
if UIImagePickerController.isSourceTypeAvailable(.photoLibrary){
let libraryPicker = UIImagePickerController.init()
libraryPicker.delegate = self
libraryPicker.sourceType = .photoLibrary
libraryPicker.mediaTypes = [kUTTypeMovie as String,kUTTypeVideo as String]
libraryPicker.allowsEditing = false
self.present(libraryPicker, animated: true, completion: nil)
}
})
let cancelButton = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
alert.addAction(camera)
alert.addAction(VideoAlbm)
alert.addAction(saveAlbum)
alert.addAction(cancelButton)
return alert
}()
self.present(aletcontroller, animated: true, completion: nil)
}
image从厨房拾取并在此处给出路径
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
if flag1 == 1{
flag1=0
guard let image1 = info[UIImagePickerController.InfoKey.originalImage]
as? UIImage else {
return
}
firstImg.image = image1 as UIImage
}
if flag2 == 2{
flag2=0
guard let image = info[UIImagePickerController.InfoKey.originalImage]
as? UIImage else {
return
}
secondImageView.image = image as UIImage
}
if flag3 == 1{
flag3=0
guard let image = info[UIImagePickerController.InfoKey.originalImage]
as? UIImage else {
return
}
thirdImageView.image = image as UIImage
}
if flag4 == 1{
flag4 = 0
guard let image = info[UIImagePickerController.InfoKey.originalImage]
as? UIImage else {
return
}
fourthImageView.image = image as UIImage
}
if flag5 == 1{
flag5 = 0
guard let image = info[UIImagePickerController.InfoKey.originalImage]
as? UIImage else {
return
}
fifthImageView.image = image as UIImage
}
dismiss(animated:true, completion: nil)
}