I'm new to Xcode development and very new to MessageKit. I'm currently following an iOS Academy video to get the messaging section of my app working (Great series of videos by the way).
I have installed the MessageKit cocoa pod (and reinstalled it like 3 times to make sure I did it right) but yet, I can't seem to use the messagesCollectionView property.
I know it exists because first, the tutorial uses it, and second, after further investigation, ITS THE FIRST ATTRIBUTE OF THE VIEW CONTROLLER
open class MessagesViewController: UIViewController,
UICollectionViewDelegateFlowLayout, UICollectionViewDataSource, UIGestureRecognizerDelegate {
/// The `MessagesCollectionView` managed by the messages view controller object.
open var messagesCollectionView = MessagesCollectionView()
/// The `InputBarAccessoryView` used as the `inputAccessoryView` in the view controller.
open lazy var messageInputBar = InputBarAccessoryView()
when I start typing out "messagesCollectionView" there is no autocomplete and I get an error that says that it cannot be found in scope. Here is my view controller
class ChatViewController: MessagesViewController {
let currentUser = Sender(senderId: "self",displayName: "Yianni Zavaliagkos")
let otherUser = Sender(senderId: "other",displayName: "Ezra Taylor")
var messages: [MessageType] = []
override func viewDidLoad() {
super.viewDidLoad()
title = "Chat"
messages.append(Message(sender: currentUser,
messageId: "1",
sentDate: Date().addingTimeInterval(-86400),
kind: .text("Hello World")))
messages.append(Message(sender: otherUser,
messageId: "2",
sentDate: Date().addingTimeInterval(-70000),
kind: .text("How is it going")))
//Errors on these next couple lines
messagesCollectionView.messagesDataSource = self
messagesCollectionView.messagesLayoutDelegate = self
messagesCollectionView.messagesDisplayDelegate = self
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)
}
}
and yes, I have implemented the MessegesDataSource and Layout and Display Delegates as well.
My first guess is that I installed the cocoa pod somehow incorrectly but I've tried everything and was hoping to be blessed by the StackOverflow Gods with an easy solution to this frustrating problem. Thanks!
You need to reload your collection, so put: messagesCollectionView.reloadData() to your viewDidLoad method. It works for me
When I am running Xcode with below codes it says "build succeeded" but on the simulator nothing is being appeared and I don't know why. Please kindly advise what to fix.
import UIKit
class ViewController: UIViewController {
let numberOfPlanets = 8
let diameterOfEarth = 24859.92 // in miles, where pole to pol
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
print("Welcome to solar system!")
print("There are \(numberOfPlanets) to explore")
print("You are currenly on the Earth, which has a circumstance of \(diameterOfEarth) miles")
firstTextView.text = "Welcome to solar system!"
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
#IBOutlet weak var firstTextView: UITextView!
}
added.
thank you Shades enter image description herefor your advice. I checked all you advised but the console is not still printing. I changed the name of "ViewController.swift" to "main.swift" to remove an error saying "expressions are not at the top level". probably it is the reason? I added the screenshot of mine for better understanding. please help.
My app stop in AppDelegate.
I am making an app which can access camera and photo library and I can upload photos in my app.
I run my app in my real iPhone from Xcode,but when I put camera access button & photo library button, my app stopped in a part AppDelegate.swift
class AppDelegate: UIResponder, UIApplicationDelegate {
and could not move.
In Cornroller,I wrote
import UIKit
class KenshinSendController:UIViewController,
UINavigationControllerDelegate,UIImagePickerControllerDelegate{
let ButtonCamera = 0
let ButtomRead = 1
let ButtonWrite = 2
var imageView:UIImageView = UIImageView()
var btnCamera:UIButton = UIButton(type: .custom)
var btnRead:UIButton = UIButton(type: .custom)
var btnWrite:UIButton = UIButton(type: .custom)
override func viewDidLoad() {
super.viewDidLoad()
imageView.frame = CGRect(x: 150, y: 100, width: 200, height: 200)
imageView.contentMode = .scaleAspectFit
view.addSubview(imageView)
btnCamera.frame = CGRect(x: 0, y: 100, width: 100, height: 100)
btnCamera.setTitle("Camera", for: .normal)
btnCamera.tag = ButtonCamera
btnCamera.addTarget(self, action: #selector(self.onClick(sender:)), for: .touchUpInside)
btnCamera.backgroundColor = UIColor.green
self.view.addSubview(btnCamera)
btnRead.frame = CGRect(x: 0, y: 200, width: 100, height: 100)
btnRead.setTitle("Read", for: .normal)
btnRead.tag = ButtomRead
btnRead.addTarget(self, action: #selector(self.onClick(sender:)), for: .touchUpInside)
btnRead.backgroundColor = UIColor.red
self.view.addSubview(btnRead)
btnWrite.frame = CGRect(x: 0, y: 300, width: 100, height: 100)
btnWrite.setTitle("Write", for: .normal)
btnWrite.tag = ButtonWrite
btnWrite.addTarget(self, action: #selector(self.onClick(sender:)), for: .touchUpInside)
btnWrite.backgroundColor = UIColor.blue
self.view.addSubview(btnWrite)
}
//ボタンクリック時に呼ばれる
#IBAction func ButtonCamera(_ sender: Any) {
}
#IBAction func ButtonRead(_ sender: Any) {
}
func onClick(sender:UIButton){
if sender.tag == ButtonCamera {
openPicker(sourceType: UIImagePickerControllerSourceType.camera)
}else if sender.tag == ButtomRead {
openPicker(sourceType: UIImagePickerControllerSourceType.photoLibrary)
}
}
//アラートの表示
func showAlert(title: String?, text: String?) {
let alert = UIAlertController(title: title, message: text, preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
present(alert, animated: true, completion: nil)
}
func openPicker(sourceType:UIImagePickerControllerSourceType){
if !UIImagePickerController.isSourceTypeAvailable(sourceType){
showAlert(title: nil, text: "利用できません")
return
}
let picker = UIImagePickerController()
picker.sourceType = sourceType
picker.delegate = self
present(picker, animated: true, completion: nil)
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
let image = info[UIImagePickerControllerOriginalImage]as! UIImage
imageView.image = image
picker.presentingViewController?.dismiss(animated: true,completion:nil)
}
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
picker.presentingViewController?.dismiss(animated: true, completion: nil)
}
}
Identity Inspector is like
and AppDelegate.swift is like
import UIKit
import Alamofire
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}
Info.plist is like
<plist version="1.0">
<dict>
<key>UILaunchStoryboardName</key>
<string></string>
<key>CFBundleGetInfoString</key>
<string></string>
<key>NSPhotoLibraryUsageDescription</key>
<string>フォトライブラリの使用許可をお願いします</string>
<key>CFBundleDisplayName</key>
<string></string>
<key>NSCameraUsageDescription</key>
<string>カメラの使用許可をお願いします</string>
<key>LSApplicationCategoryType</key>
<string></string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
Error message is like Thread 1:signal SIGABRT
I used TabBarController,it is like
Connection Inspector is like
You need to give photo and camera access in info.plist file.
Privacy - Camera Usage Description
Privacy - Photo Library Usage Description
The following answers about iOS 10 will only affect the app's review process and will build and run without errors, so adding these will change nothing in a sense of the app's ability to work:
Privacy - Camera Usage Description: purpose of your app using camera
Privacy - Photo Library Usage Description: purpose of your app using Photo
The issue you are experiencing is usually due to a broken reference your storyboard. You may have changed an outlet name or an IBAction method.
You can check this by selecting the view controller in the storyboard and looking for a ! next to any references. If there is a !, click the X to delete the reference.
See attached image (look at down arrow)
You can also look in the code for an empty circle next to your outlets or actions.
I tested your code, and it's perfect, there is no error in your code.
It seems, you have a wrong link with Interface Builder element in your storyboard. Reason for this kind of error is, wrong link (attachment) of interface builder in storyboard with your view controller.
Please check your initial storyboard & especially initial view controller, its attachment with connection inspector & Identity inspector.
Identity Inspector: Your view controller is properly integrated with current project or not.
Connection inspector: You don't have any wrong link of interface builder.
Share here snapshot of your initial storybaord & view controller also, with identity inspector and connection inspector.
Edit: According to your current snap shot, you may have used Tabbar controller as initial view controller (and two connections are incoming for current view controller you have shared.) but not shared information about tabbar controller here. Share complete snapshot (and source code) of your story board to get exact resolution.
From iOS 10, you have to add privacy descriptions in your info.plist file unless your app will crash when request permission. In your case, you must add:
Privacy - Camera Usage Description : purpose of your app using camera
Privacy - Photo Library Usage Description : purpose of your app using Photo
Swift App Xib - Second ViewController - Labels not showing for 30 seconds but Buttons and other controls showing immediately. What could this be / how can I solve this?
Xcode 7.3.1
Swift 2
This is happening on the device and in the simulator
---> Video of Issue <-----
I present from first viewController like this:
secondViewController.user = user
self.presentViewController(secondViewController, animated: true, completion: nil)
Second View Controller
override func viewDidLoad() {
super.viewDidLoad()
print("ViewController did load")
print("selected facility is: ", user?.selectedFacility)
// Do any additional setup after loading the view.
}
// required init(coder aDecoder: NSCoder) {
// super.init(nibName: "ListViewController", bundle: NSBundle.mainBundle())
// }
override func awakeFromNib() {
print("awake from nib")
}
override func viewWillAppear(animated: Bool) {
print("viewWillAppear")
}
override func viewDidAppear(animated: Bool) {
print("viewDidAppear")
}
override func viewDidDisappear(animated: Bool) {
print("viewDidDisappear")
}
UPDATE
If I set the text in viewDidLoad the label appears at the same time as everything else.
override func viewDidLoad() {
super.viewDidLoad()
print("ListViewController did load")
labelX.text = "heyVC"
Adding the outlet itself didn't change anything. It was actually programmatically setting the text that fixed it. I think this is a bug in IB. I will file with apple.
Bug number is 27029176
See if you have set some custom font of label and the font file could not be found by system(like if you have deleted the file). If system font is not set in Label , try setting system font and re-run to confirm.
Are you doing anything with NSURL / NSMutableURLRequest / dataTaskWithRequest?
I am experiencing exactly the same thing with the 30sec delay. When I am commenting out my code which is fetching data from an URL (with the above mentioned methods) the labels are showing instantly. When the code is executed, the labels are displayed with a delay. I guess the fetching somehow makes things asynchronous.
Not exactly a solution but maybe a starting point for further research. Please let me/us know if you have new ideas or the solution. Thanks. :-)
Since the recent update to Xcode 7, I have found that my webView will no longer load, it will only show a white screen.
I have searched for a solution, to no avail.
I have coded the webView connection as follows:
class ViewController: UIViewController {
#IBOutlet weak var webviewInstance: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
// Connect UIWebView to the ordering page
let url = NSURL (string: "http://www.google.com");
let requestObj = NSURLRequest(URL: url!);
webviewInstance.loadRequest(requestObj);
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
I would greatly appreciate any help with this.
You have to check the app plist file and add the AppTransportSecurity.
Open your plist file and add this. Search for AppTransportSecurity
<key>NSAppTransportSecurity</key>
<dict>
<!--Include to allow all connections (DANGER)-->
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
If you don't add the ATS in your PLIST your link are ignored/blocked. I hope this can help you
A while back I remember reading a question here on SO saying that not implementing
- webView:shouldStartLoadWithRequest:navigationType:
from UIWebViewDelegate was causing problems.
If that don't solve the issue, you can use the delegate methods to debug your problem