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

Removing a value at a specified index of a dictionary swift
I am getting blank user_intrest from facebook in my ios app.
Images animation in UIImageview not smooth
QQmlApplicationEngine failed to load component: […] module “QtQuick” is not installed
2x Images retrieved from .xcassets sometimes give 1x instead
Facebook login trying to translate obj C to swift
Why are my testflight betas not getting invited?
Air application not packaging for iOS (air sdk 17)
Animated Image animationRepeatCount CollectionViewCell
Get working Ionic + ngCordova + background geolocation
I am getting Error Domain=NSPOSIXErrorDomain Code=2 when making API request from iOS
iOS : Loading GMSMapView consuming loads of memory and decrease in FPS(Frames Per Second) rate
iAd Won't Load Test Ads
UIImagePickerController hiding status bar iOS 8
Blur an image via objective-c
Xcode stalls on “loading” when trying to create new project

Categories

HOME
validation
logstash
office-js
load
blogs
cql3
fpdf
normalization
application-cache
addeventlistener
socrata
activerecord
asciidoc
wso2ei
wavelet
pouchdb
sonata-admin
nanotime
numericupdown
flow
h.264
snort
smallbasic
apache-httpcomponents
angular-ngmodel
asp.net-identity-2
kprobe
whatsapi
jtapi
cloudinary
photo-gallery
vrtk
nav
gradient-descent
bezier
protobuf-3
uitabbarcontroller
gradle-tooling-api
qmake
backwards-compatibility
botkit
sdcc
pseudo-element
strip-tags
mrtg
ammonite
reactivex
master-data-management
playback
manual
bosh-deployer
breach-attack
vs-2015-preview
blocking
hard-drive-failure
vispy
hapi.js
vb4android
webclient-download
sliding
android-popupwindow
pakyow
occam-pi
egl
kinto
android-gpuimageview
wt
sketching
simperium
alt
targetinvocationexception
java-client
sendto
django-supervisor
magic-unipaas
xsltforms
disk-io
dfsort
batman.js
blueprint
django-endless-pagination
execcommand
siblings
xcache
git-gui
uptime
html5-apps
domain-mapping
code-structure
maven-bundle-plugin
adaboost
graphiti-js
quilt
consistent-hashing
bapi
payment-services
facebook-authentication
blackberry-os-v5
formsauthentication
.net-1.1
alivepdf
renderaction
seam-conversation
xtratreelist
markitup
gedcom

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