TableViewCell pass data to ViewController (Parse.com)? - ios

Tell me what can be a mistake. I have 6 columns, two columns belong to TableViewCell. The other 4 belong to the ViewController. How do I tie the rows correctly so that the match information matches its row in TableViewCell.
import UIKit
import Parse
class DetailTennisViewController: UIViewController {
#IBOutlet weak var imageTennis: UIImageView!
#IBOutlet weak var outClose: UIButton!
#IBOutlet weak var titleTennis: UILabel!
#IBOutlet weak var textTennis: UITextView!
#IBOutlet weak var progTennis: UILabel!
#IBAction func closeOut(_ sender: Any) {
dismiss(animated: false, completion: nil)
}
var tenises : Tennis?
func configureButton() {
outClose.layer.cornerRadius = 0.5 * outClose.bounds.size.width
outClose.clipsToBounds = true
}
override func viewDidLoad() {
super.viewDidLoad()
loadTennis()
configureButton()
}
func loadTennis () {
let qwery = PFQuery(className: "tennis")
qwery.getFirstObjectInBackground() { (object,error) ->Void in
if error == nil {
self.textTennis.text = object!["textTen"] as? String
self.progTennis.text = object!["progTen"] as? String
self.titleTennis.text = object!["titleTen"] as? String
let imageFile = object!["tenImage"] as? PFFile
imageFile?.getDataInBackground() { (data:Data?, error:Error?)->Void in
if error == nil {
if let imageData = data {
self.imageTennis.image = UIImage(data: imageData)
}
}
}
}
}
}
}
How to make the data string Parse.com How to make the data TableViewCell cells corresponded to the description ViewController. In my code, when the cell is opened, the same data is displayed. I uploaded 4 events and information about them. So the information about them opens up the same. How to make the one that is indicated by their "objectId"

Related

How can I get values of response variable in other view in swift ...when I try to access this variable it returns nil...need to solve this

I just want to get all the values of response variable in (Agent view controller class) when I try to get using object it returns nil I have tried in many ways but still getting nil....in agent view controller I'm assigning all those runtime values to uitextview
import UIKit
class LoginViewController: UIViewController {
weak var delegateL:AgentprofileViewController!
var user : [UserModel] = []
let mm = Usersmanager()
//MARK:-- Outlets
#IBOutlet public weak var txtPhoneNumber: UITextField!
#IBOutlet public weak var txtPassword: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
}
//Functions
#IBAction func btnLogin(_ sender: Any) {
//below is the response variable which I want in other (Agent view controller class)
let response = mm.alluser(phoneNo: txtPhoneNumber.text!, Password: txtPassword.text!)
if response.count ?? 0 > 0
{
//uncom
delegateL.runtimeid? = response[0].u_id
delegateL.runtimename? = response[0].u_name!
delegateL.runtimephone? = response[0].phoneNumber!
delegateL.runtimepassword? = response[0].password!
delegateL.runtimeaddress? = response[0].address!
delegateL.runtimerid? = response[0].r_id!
delegateL.runtimername? = response[0].r_name!
print(response[0].u_id)
print(response[0].u_name)
print(response[0].password)
print(response[0].phoneNumber)
print(response[0].address)
print(response[0].r_id)
print(response[0].r_name)
if response[0].r_name=="Agent"
{
let next : tabViewController = self.storyboard?.instantiateViewController(withIdentifier: "tabViewController") as! tabViewController
self.navigationController?.pushViewController(next, animated: true)
showalertforloginsuccess()
print("Login Successfull")
//Passing view to the next view if login is succesfull
// let next : HomeViewController = self.storyboard?.instantiateViewController(withIdentifier: "HomeViewController") as! HomeViewController
// self.navigationController?.pushViewController(next, animated: true)
}
else{
print("Login Succesfull but login person is not agent")
}
}
else
{
showalertforloginfail()
print("Not Login")
}
}
This one is Agent Controller class where I want to access response variable values
import UIKit
class AgentprofileViewController: UIViewController {
#IBOutlet weak var txtid: UITextView!
#IBOutlet weak var txtname: UITextView!
#IBOutlet weak var txtphone: UITextView!
#IBOutlet weak var txtrid: UITextView!
#IBOutlet weak var txtpass: UITextView!
#IBOutlet weak var txtrname: UITextView!
#IBOutlet weak var txtaddress: UITextView!
var runtimeid:Int? = 0
var runtimename:String?=""
var runtimepassword:String?=""
var runtimeaddress:String?=""
var runtimephone:String?=""
var runtimerid:Int? = 0
var runtimername:String?=""
override func viewDidLoad() {
super.viewDidLoad()
//below all runtime variables contain nil
print(runtimeid)
print(runtimename)
print(runtimeaddress)
print(runtimepassword)
print(runtimephone)
print(runtimerid)
print(runtimername)
result()
}
override func viewWillAppear(_ animated: Bool) {
self.tabBarController?.navigationItem.title = "Profile"
}
func result() {
//uncom
//below is the error(txtid...contain nill while wrapping)
txtid.text = "\(String(describing: runtimeid))"
txtname.text = runtimename
txtpass.text = runtimepassword
txtphone.text = runtimephone
txtaddress.text = runtimeaddress
txtrid.text = "\(String(describing: runtimerid))"
txtrname.text = runtimername
}
}

How can I passing data UIViewContoller from UIView in swift3

How can i passing data uiviewController from uiview
I am Using function but it was not working
protocol name is startcalldelegate and function name is startcall
UIView Code
protocol StartCallDelegate: class {
func startCall(localNickname :String, remoteNickname :String)}
class CardView: UIView {
let managedObjectContext = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
weak var delegate: CardViewDelegate?
weak var socketdelegate: StartCallDelegate?
#IBOutlet weak var UserPhoto: UIImageView!
#IBOutlet weak var UserNickName: UILabel!
#IBOutlet weak var UserAge: UILabel!
#IBOutlet weak var UserPeople: UILabel!
var localNickname: String = ""
var remoteNickname: String = ""
#IBAction func SendMessage(_ sender: Any) {
print("SendMessage")
//print(localNickName)
//print(UserNickName.text!)
}
#IBAction func SendVideoCall(_ sender: Any) {
print("SendVideoCall")
let entityDescription = NSEntityDescription.entity(forEntityName: "Profile", in: managedObjectContext)
let request = NSFetchRequest<NSFetchRequestResult>()
request.entity = entityDescription
do {
let objects = try managedObjectContext.fetch(request)
if objects.count > 0 {
let match = objects[0] as! NSManagedObject
localNickname = match.value(forKey: "nick") as! String
} else {
print("Nothing founded")
}
} catch {
print("error")
}
remoteNickname = UserNickName.text!
socketdelegate?.startCall(localNickname: localNickname, remoteNickname: remoteNickname)
delegate?.VideoChatSegue()
}
}
UIViewcontroller Code
class ViewController: UIViewcontroller, StartCallDelegate {
var localNickname: String = ""
var remoteNickname: String = ""
override func viewDidLoad() {
super.viewDidLoad()
print(localNickname)
print(remoteNickname)
}
func startCall(localNickname: String, remoteNickname: String) {
print("Action startcall func")
self.localNickname = localNickname
self.remoteNickname = remoteNickname
}
startCall func not working
You need to define delegate in viewcontroller' ViewDidLoad
let objOardView = CardView() // this is only test purpose
objOardView.socketdelegate = self

How to make label.text equal to a custom object's value in an array?

Currently I have some custom JSON objects:
class JSONObjects {
var airbnbUS: String
var airbnbLocal: String
var image: URL
init(airbnbUS: String, airbnbLocal: String, image: URL){
self.airbnbUS = airbnbUS
self.airbnbLocal = airbnbLocal
self.image = image
}
After parsing the json I then transfer an array of the custom object through a segue to be presented on a detail view controller:
var jsonObjectsArray: [JSONObjects] = []
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "practiceTableToDetailSegue" {
if let detailVC = segue.destination as? PracticeDetailViewController {
self.jsonObjectsArray = detailVC.jsonObjectArray
}
}
}
On the detail view controller I would like to take elements of the custom object array and show them via a label but when I try to access the array the only options I get are
.count, .capacity, etc.
I'm trying to present the custom object values in the labels and imageView but its not giving me the option to access the custom object values:
class PracticeDetailViewController: UIViewController {
var jsonObjectArray: [JSONObjects] = []
#IBOutlet weak var topLabel: UILabel!
#IBOutlet weak var bottomLabel: UILabel!
#IBOutlet weak var image: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
self.topLabel.text = jsonObjectArray.airbnbUS //DOES NOT WORK!
self.bottomLabel.text = jsonObjectArray.airbnbLocal //DOES NOT WORK!
self.image.image = UIImage(data: jsonObjectArray.image) //DOES NOT WORK!
}
}
You're trying to access the properties of your JSONObjects on the array rather than the elements of the array.
Try this:
self.topLabel.text = jsonObjectArray[0].airbnbUS //DOES WORK!
self.bottomLabel.text = jsonObjectArray[0].airbnbLocal //DOES WORK!
self.image.image = UIImage(data: jsonObjectArray[0].image) //DOES WORK!
Also, a style comment: I'd recommend making your classes singular (i.e. JSONObject rather than JSONObjects). When you instantiate an object you're only making one object, not a bunch of JSONObjects
try something like this:
class PracticeDetailViewController: UIViewController {
var jsonObjectArray: [JSONObjects] = []
#IBOutlet weak var topLabel: UILabel!
#IBOutlet weak var bottomLabel: UILabel!
#IBOutlet weak var image: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
self.jsonObjectArray.append(JSONObjects(airbnbUS: "airbnbUS", airbnbLocal: "airbnbLocal", image: URL(string: "url")!))
self.topLabel.text = jsonObjectArray[0].airbnbUS
self.bottomLabel.text = jsonObjectArray[0].airbnbLocal
do {
let data = try Data(contentsOf: jsonObjectArray[0].image)
self.image.image = UIImage(data: data)
} catch {}
}
}

Data persistence after call to webservice iOS

Sorry for my English.
I have many problems in achieving data persistence after call the webservice .
Everything works correctly but I need to use that data in other methods .
As seen in the image once charge data on the screen then I want to give the user the option to use them well or load new data . But not as saving the data recovery webservice .
I was trying to use NSUserDefault but neither work .
From already thank you very much , any response is helpful .
Regards!
ViewController:
class ViewController: UIViewController {
let defaults = NSUserDefaults.standardUserDefaults()
#IBOutlet weak var myLabel2: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let newVC : SecondViewController = segue.destinationViewController as! SecondViewController
let telefono = myLabel2.text!
newVC.recibirString = telefono
}
#IBAction func mostrarAlgo(sender:AnyObject) {
//something
}
}
SecondViewController:
class SecondViewController: UIViewController {
let defaults = NSUserDefaults.standardUserDefaults()
var tel: String = ""
#IBOutlet weak var myLabel1: UITextField!
#IBOutlet weak var myLabel3: UITextField!
#IBOutlet weak var myLabel4: UITextField!
#IBOutlet weak var myLabel5: UITextField!
#IBOutlet weak var myLabel6: UITextField!
#IBOutlet weak var myLabel7: UITextField!
#IBOutlet weak var myLabel8: UITextField!
var recibirString = String()
override func viewDidLoad() {
super.viewDidLoad()
myLabel1.text = recibirString
performRequestAndUpdateUI2(myLabel1.text!)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func performRequestAndUpdateUI2(tel:String) {
WebService.llamarWebService (tel,completionHandler: { datos in
guard datos.count == 5 else {
self.myLabel8.text = ("El número ingresado no está registrado.")
return
}
guard datos[0] as! String == "OK" else {
print("not everything was OK")
return
}
dispatch_async(dispatch_get_main_queue()) {
self.myLabel3.text = datos[0] as? String
self.myLabel4.text = datos[1] as? String
self.myLabel5.text = datos[2] as? String
self.myLabel6.text = datos[3] as? String
self.myLabel7.text = datos[4] as? String
self.myLabel8.text = ("Usted está registrado.")
//need save this data
}
})
}
#IBAction func guardarDatos(sender: AnyObject) {
// do something
}
}
WebService:
class WebService{
var telefono = ""
class func llamarWebService(telefono:String, completionHandler: (datos:NSArray)->()){
let urlPath = "http://xxxxxxxxxxx.com.ar/xxxxxxxxxx/forwarder_number?phone=\(telefono)"
let url = NSURL(string: urlPath)
let session = NSURLSession.sharedSession()
var arreglo:NSArray!
let task = session.dataTaskWithURL(url!,completionHandler: {data,response,error -> Void in
if (error != nil){
print(error?.localizedDescription)
}
let nsdata: NSData = NSData(data: data!)
arreglo = self.retornarDatos(nsdata)
completionHandler(datos: arreglo)
})
task.resume()
}
class func retornarDatos(nsdata: NSData)-> Array<String>{
let datos = NSString(data:nsdata,encoding: NSUTF8StringEncoding)
let partes = datos?.componentsSeparatedByString(",")
var arreglo : [String] = []
for i in partes!{
arreglo.append(i)
}
return arreglo
}
}

Images not showing up while attempting to convert PFFile to UIImage and segue it

My code isnt functioning correctly when I click a cell and want it to segue and show the same information on a new screen.
The Text is working perfectly and showing up in the new view but the images just wont appear. I am attempting to convert a PFFile from Parse into a UIImage and use it in a array so that when I click into the cell and it displays the view it will load the correct images and data. I am on Xcode 7 Beta 5. It is giving me no error but still isnt displaying the data correctly.
Here is the necessary Code, if any more is required to solve the issue I will be glad to provide it.
(Whats in the first class)
import Foundation
import Parse
class mainScreen: UIViewController, UICollectionViewDataSource {
var imageArray = [PFFile]()
var theDownloadedImages = [UIImage()]
var nameArray = [String]()
var priceArray = [String]()
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)
{
if segue.identifier == "cellInfo"
{
let indexPaths = self.collectionView!.indexPathsForSelectedItems()!
let indexPath = indexPaths[0] as NSIndexPath
let CI = segue.destinationViewController as! cellInfo
let imageForCell = self.imageArray[indexPath.row] as PFFile
imageForCell.getDataInBackgroundWithBlock { (data, error) -> Void in
if let downloadedImage = UIImage(data: data!) {
self.theDownloadedImages.append(downloadedImage)
CI.image = self.theDownloadedImages[indexPath.row]
CI.name = self.nameArray[indexPath.row]
CI.price = self.priceArray[indexPath.row]
}
}
}
}
(For the second Class)
class cellInfo: UIViewController {
#IBOutlet weak var CILocation: UILabel!
#IBOutlet weak var CIImage: UIImageView!
#IBOutlet weak var CIPrice: UILabel!
#IBOutlet weak var CIName: UILabel!
var image = UIImage()
var name = String()
var price = String()
var location = String()
override func viewDidLoad() {
super.viewDidLoad()
self.CIImage.image = self.image
self.CIName.text = self.name
self.CIPrice.text = self.price
self.CILocation.text = self.location
}

Resources