snsの勉強のために、コードを書いています。
Expected declarationエラーがコマンド+Bで出てしまいます。
原因として
1 カメラの使い方が間違っている
2 extentionの使い方が間違っている
3 そもそもコードの書き方が間違っている
のどれかだとは思いますが、僕の能力ではわかりません。
解決方法がわかる方、どうぞよろしくお願いします。
学習のため、xcode7.0のバージョンで記しています。
swift
1import UIKit 2import Photos 3 4class PostViewController: UIViewController { 5 6 7 //@IBOutlet var navigationBar: UINavigationItem! 8 9 @IBOutlet var navigationBar: UINavigationBar! 10 11 @IBOutlet var userProfileImage: UIImageView! 12 13 14 @IBOutlet var postText: UITextView! 15 16 17 @IBOutlet var postImage: UIImageView! 18 19 20 @IBOutlet var usernameLabel: UILabel! 21 22 @IBOutlet var createdAt: UILabel! 23 24 @IBOutlet var backButton: UIBarButtonItem! 25 @IBOutlet var postButton: UIBarButtonItem! 26 27 private var PostImage: UIImage 28 29 30 31 32 override func viewDidLoad() { 33 super.viewDidLoad() 34 35 // navigationBar.tintColor = UIColor.whiteColor() 36 37 navigationBar.tintColor = UIColor.whiteColor() 38 navigationBar.titleTextAttributes = [NSFontAttributeName: UIColor.whiteColor()] 39 navigationBar.barTintColor = UIColor(hex: "1A237E") 40 41 userProfileImage.layer.cornerRadius = userProfileImage.layer.bounds.width/2 42 userProfileImage.clipsToBounds = true 43 44 postText.text = "" 45 postText.becomeFirstResponder() 46 47 //notificationcenter 48 NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyBoardWillHide:", name: UIKeyboardWillHideNotification, object: nil) 49 NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyBoardWillShow:", name: UIKeyboardWillShowNotification, object: nil) 50 51 } 52 53 override func didReceiveMemoryWarning() { 54 super.didReceiveMemoryWarning() 55 // Dispose of any resources that can be recreated. 56 } 57 58 deinit { 59 NSNotificationCenter.defaultCenter().removeObserver(self) 60 } 61 62 63 func keyboardWillHide(notificaton: NSNotification){ 64 65 self.postText.contentInset = UIEdgeInsetsZero 66 self.postText.scrollIndicatorInsets = UIEdgeInsetsZero 67 68 } 69 70 func keyboardWillShow(notificaton: NSNotification){ 71 let userInfo = notificaton.userInfo ?? [:] 72 // let keyboardSize = (userInfo[UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue().size 73 let keyboardSize = (userInfo[UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue().size 74 75 self.postText.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: keyboardSize.height+10, right: 0) 76 self.postText.scrollIndicatorInsets = self.postText.contentInset 77 78 79 80 } 81 82 83 @IBAction func backButton_Clicked(sender: AnyObject) { 84 85 postText.resignFirstResponder() 86 dismissViewControllerAnimated(true, completion: nil) 87 88 } 89 90 91 @IBAction func postButtonClicked(sender: AnyObject) { 92 93 postText.resignFirstResponder() 94 dismissViewControllerAnimated(true, completion: nil) 95 } 96 97 98 99 100} 101 102extension PostViewController:UIImagePickerControllerDelegate,UINavigationControllerDelegate { 103 @IBAction func PickFeaturedImage(sender: AnyObject) { 104 105 let authorization = PHPhotoLibrary.authorizationStatus() 106 if authorization == .NotDetermined { 107 PHPhotoLibrary.requestAuthorization({ (status) -> Void in 108 dispatch_async(dispatch_get_main_queue(), { () -> Void in 109 self.PickFeaturedImage(sender) 110 }) 111 }) 112 return 113 114 if authorization == .Authorized { 115 let controller = ImagePickerSheetController() 116 controller.addAction(ImageAction(title: NSLocalizedString("Take a Photo or Video", comment: "ActionTitle"), secondaryTitle: NSLocalizedString("Use this one", comment: "ActionTitle"), handler: { (_) -> () in 117 self.presentCamera() 118 119 }, secondaryHandler: { (action, numberOfPhoto) -> () in 120 controller.getSelectedImagesWithCompletion({ (images) -> Void in 121 self.PostImage = images[0] 122 self.postImage.image = self.PostImage 123 }) 124 })) 125 controller.addAction(ImageAction(title: NSLocalizedString("Cancel", comment: "ActionTitle"), style: .Cancel, handler: nil)) 126 127 presentViewController(controller, animated: true, completion: nil) 128 } 129 130 } 131 132 func presentCamera() { 133 let imagePicker = UIImagePickerController() 134 imagePicker.allowsEditing = false 135 imagePicker.delegate = self 136 imagePicker.sourceType = UIImagePickerControllerSourceType.Camera 137 self.presentViewController(imagePicker, animated: true, completion: nil) 138 139 } 140 141 func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject :AnyObject]!) { 142 self.postImage.image = image 143 self.dismissViewControllerAnimated(true, completion: nil) 144 145 } 146 147}
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。