ios


Segue to chat viewcontroller


I have included images to hopefully make this easier to understand. My FirstViewController has a collection view with a list of users from my firebase database.When I click on the users I am segued to a DetailedViewController that has more information about the user that was clicked. Within that viewController, the goal is to click on the compose button and segue to a viewController that allows me to chat with the user, whose profile I clicked on.
I have gotten as far as this for segueing from DetailedViewController to Message user 1.
#IBAction func SendMessage(_ sender: Any) {
performSegue(withIdentifier: "chat", sender: self)
}
I am not sure how to make sure I am sending the particular user I click on a message.
This is how I am passing data from FirstViewController to DetailedViewController.
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "details" {
if let indexPaths = self.CollectionView!.indexPathsForSelectedItems{
let vc = segue.destination as! BookDetailsViewController
let cell = sender as! UICollectionViewCell
let indexPath = self.CollectionView!.indexPath(for: cell)
let post = self.posts[(indexPath?.row)!] as! [String: AnyObject]
let Booked = post["title"] as? String
vc.Booked = Booked
print(indexPath?.row)
} }
One route to take is in your DetailViewController class, or whatever class you have implementing "performSegue(withIdentifier:, sender:)", add this:
override public func prepare(for segue: UIStoryboardSegue, sender: Any?) {
guard segue.identifier == "chat", let dest = segue.destination as? ChatViewController else {
return
}
dest.person = self.person
}
I don't know how you have the person's properties declared but if person is an object, do what I have above, if the it's individual properties, do
dest.name = self.name
dest.number = self.number //etc
prepare(for segue:, sender:) allows you to intercept any segue from that class and set up any variable need before the performSegue(...) executes. Make sure you identify the segue in some way otherwise the code will execute on all segues implemented in the class. In my example I used your segue's identifier.

Related Links

How to add UIRefreshControl on UITableView bottom?
Presenting VC embedded in a NavController from AppDelegate
This certificate has an invalid issuer Apple Push Services
How to handle sessions with QuickBlox in iOS
getting nil value while calling api (alamofire)
iOS Convert m4a to amr before uploading
UIWebView fast scrolling to show large image lead to memory warning crash
Changing User Email and Password with Swift and Firebase
is there a clear understanding of IQWidgets library
Change constraint second item
Safari won't wait for user for Google sign-in redirect to iOS application
Swift - Download a video from distant URL and save it in an photo album
Declaration for an UIImage in NSObject
SequenceType with DictionaryGenerator - issues with Struct when Class works fine?
How to use object in whole class?
One tabBarItem draws two images occasionally

Categories

HOME
graph
hadoop
opencl
sharepoint-2013
youtube
android-activity
rtmp
tcl
genetic-algorithm
turing
fpdf
svg.js
logback
plotly
prestashop-1.7
google-maps-sdk-ios
librsvg
calabash-android
rebus
ssrs-tablix
libssh
garmin
gyroscope
textmatebundles
revitpythonshell
ghost-blog
dotnetbar
co
ibm-datapower
c-strings
broker
mouseevent
dsl
number-formatting
c++builder-5
clappr
jtapi
cloudinary
google-shared-contacts
jformattedtextfield
chamilo-lms
data-science
ecmascript-4
signing
extjs4
jpype
linear
php-5.5
freerdp
zfs
rtems
azure-cdn
manifoldjs
html-form
domdocument
complement
maven-versions-plugin
column-oriented
graph-traversal
jeditorpane
zenity
mailcore2
mysql-notifier
webpagetest
blpapi
yapdatabase
java-gstreamer
chunk-templates
netbsd
user-registration
google-swiffy
solr-boost
generalization
reactive-cocoa-3
isql
laravel-validation
catalina.out
dynamic-data-display
globus-toolkit
controlsfx
twill
data-quality
android-c2dm
simpleaudioengine
location-client
bochs
rcu
locomotivejs
cakephp-2.1
guvnor
libavg
documentviewer
harvest
zmodem
myisam
seam-conversation
fogbugz-on-demand

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App