我有一个UIImageView,允许用户放置和保存图像,直到它可以保存.问题是,我无法弄清楚如何实际保存和检索我放在视图中的图像.
我检索并将图像放在UIImageView中,如下所示:
//Get Image
- (void) getPicture:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = (sender == myPic) ? UIImagePickerControllerSourceTypeCamera : UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:picker animated:YES];
[picker release];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage (UIImage *)image editingInfo:(NSDictionary *)editingInfo {
myPic.image = image;
[picker dismissModalViewControllerAnimated:YES];
}
Run Code Online (Sandbox Code Playgroud)
它在我的UIImageView中显示所选图像就好了,但我不知道如何保存它.我正在Core Data中保存视图的所有其他部分(主要是UITextfield).我搜索并搜索过,并尝试了人们建议的许多代码,但要么我没有正确输入代码,要么这些建议不能用我设置代码的方式.这可能是前者.我想使用相同的操作(保存按钮)将图像保存在UIImageView中我用来保存UITextFields中的文本.这是我如何保存我的UITextField信息:
// Handle Save Button
- (void)save {
// Get Info From UI
[self.referringObject setValue:self.myInfo.text forKey:@"myInfo"];
Run Code Online (Sandbox Code Playgroud)
就像我之前说过的那样,我已经尝试了几种方法来实现它,但无法掌握它.在我生命中我第一次想要对无生命的物体造成身体伤害,但我已经设法克制自己.
我希望能够将用户放置在应用程序文档文件夹中的UIImageView中的图像保存,然后能够检索它并将其放在另一个UIImageView中,以便在用户将该视图推送到堆栈时显示.任何帮助是极大的赞赏!
我已经阅读了文档,通过他们精彩的Playground示例,搜索了SO,并达到了我的google-fu的范围,但我不能为我的生活包围我如何使用ReactiveSwift.
鉴于以下......
class SomeModel {
var mapType: MKMapType = .standard
var selectedAnnotation: MKAnnotation?
var annotations = [MKAnnotation]()
var enableRouteButton = false
// The rest of the implementation...
}
class SomeViewController: UIViewController {
let model: SomeModel
let mapView = MKMapView(frame: .zero) // It's position is set elsewhere
@IBOutlet var routeButton: UIBarButtonItem?
init(model: SomeModel) {
self.model = model
super.init(nibName: nil, bundle: nil)
}
// The rest of the implementation...
}
Run Code Online (Sandbox Code Playgroud)
....如何使用ReactiveSwift初始化SomeViewController值SomeModel,然后SomeViewController在SomeModel …
作为这个问题的后续,收到了这个梦幻般的答案,并使用以下示例...
class Model {
let mapType = MutableProperty<MKMapType>(.standard)
}
class SomeViewController: UIViewController {
let viewModel: Model
var mapView: MKMapView!
init(viewModel: Model) {
self.viewModel = viewModel
super.init(nibName: nil, bundle: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
mapView = // Create the map view
viewModel.mapType.producer.startWithValues { [weak self] mapType in
self?.mapView.mapType = mapType
}
// Rest of bindings
}
// The rest of the implementation...
}
class SomeOtherViewController: UIViewController {
let viewModel: Model
var segmentedControl: UISegmentedControl!
init(viewModel: Model) …Run Code Online (Sandbox Code Playgroud)