こんにちは皆、ボタンの内側にあるセルを更新できるかどうか疑問に思っていましたか?私はボタンが押されたコードを持っていて、あなたの緯度/経度を取得してそれらを印刷しますが、今度は他の素早いファイルのLatとLngセルを更新しようとしていますCoordinatesAltitudeDegreesTableViewCell.swift 現在のところ私のテーブルビュー関数はうまくいくように見え、viewControllerの関数でセルの更新をテストしています。緯度/経度の変数がスコープ内にあるのでボタンで表ビューセルを更新する
私の質問は、ボタンでこれらの機能を入れてとにかくある
追記:2日間の解決策を探してIVEと私は任意のページを見つけるように見えることができること私を助けてくれ、うまくいけば、これは、再投稿をイマイチと
*再び事前に続い申し訳ありませんがある場合は、申し訳ありませんが、私は迅速なプログラミングに非常に新しいです
import UIKit
import Alamofire
import SwiftyJSON
import CoreLocation
import MapKit
class myTableViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, CLLocationManagerDelegate{
//----------------------
// Buttons and Variables
//----------------------
var lastLocation: CLLocation? = nil
@IBOutlet weak var tableView: UITableView!
@IBAction func generateInfo(sender: AnyObject) {
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
let lat: Double! = lastLocation?.coordinate.latitude
let lng: Double! = lastLocation?.coordinate.longitude
let alt: Double! = lastLocation?.altitude
print(lat)
print(lng)
print(alt)
locationManager.stopUpdatingLocation()
} // end of button
//--------------
// Main Function
//--------------
override func viewDidLoad(){
super.viewDidLoad()
print("Hello World")
self.tableView.dataSource = self
self.tableView.delegate = self
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
//-------------------
// LOCATION FUNCTIONS
//-------------------
// Represents Location Manager
lazy var locationManager: CLLocationManager = {
let manager = CLLocationManager()
manager.delegate = self
manager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
return manager
}()
// Location Authorization Function
func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus){
if case .authorizedWhenInUse = status {
manager.requestLocation()
} else {
print("yeah... that didn't work")
}
}
// Location Error handle
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
print("that didn't work")
}
// Location Object
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]){
if let location = locations.first {
lastLocation = location
}
}
//--------------------
// TABLEVIEW FUNCTIONS
//--------------------
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.row == 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: "imageCellCustomCell", for: indexPath) as! ImageCellTableViewCell
return cell
}
else if indexPath.row == 1{
let cell = self.tableView.dequeueReusableCell(withIdentifier: "coordinatesAltitudeDegreesCustomCell", for: indexPath) as! CoordinatesAltitudeDegreesTableViewCell
cell.latLabel.text = "text"
return cell
}
else if indexPath.row == 2{
let cell = tableView.dequeueReusableCell(withIdentifier: "censusGeographyCustomCell", for: indexPath) as! CensusGeographyTableViewCell
return cell
}
else if indexPath.row == 3{
let cell = tableView.dequeueReusableCell(withIdentifier: "nearestAddressCustomCell", for: indexPath) as! NearestAddressTableViewCell
return cell
}
else if indexPath.row == 4{
let cell = tableView.dequeueReusableCell(withIdentifier: "populationCustomCell", for: indexPath) as! PopulationTableViewCell
return cell
}
else if indexPath.row == 5{
let cell = tableView.dequeueReusableCell(withIdentifier: "ethnicityCustomCell", for: indexPath) as! EthnicityTableViewCell
return cell
}
else if indexPath.row == 6{
let cell = tableView.dequeueReusableCell(withIdentifier: "raceCustomCell", for: indexPath) as! RaceTableViewCell
return cell
}
else if indexPath.row == 7{
let cell = tableView.dequeueReusableCell(withIdentifier: "ageCustomCell", for: indexPath) as! AgeTableViewCell
return cell
}
else if indexPath.row == 8{
let cell = tableView.dequeueReusableCell(withIdentifier: "populationPyramidCustomCell", for: indexPath) as! PopulationPyramidTableViewCell
return cell
}
else {
let cell = tableView.dequeueReusableCell(withIdentifier: "houseHoldCustomCell", for: indexPath) as! HouseHoldTableViewCell
return cell
}
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.row == 0 {
return 300
}
else if indexPath.row == 1{
return 130
}
else if indexPath.row == 2{
return 100
}
else if indexPath.row == 3{
return 100
}
else if indexPath.row == 4{
return 90
}
else if indexPath.row == 5{
return 110
}
else if indexPath.row == 6{
return 200
}
else if indexPath.row == 7{
return 300
}
else if indexPath.row == 8{
return 300
}
else {
return 360
}
}
}
に設定するたびに呼び出されましたでしょう
デバッガでちょっとゾニイリー、私はそれが戻ってコメントするのに非常に時間がかかったが、セリあなたにお礼を言います。私は今これを実装しようとしていますが、あなたのコードが何を言っているのかを実際に理解することができます。 –
@MaclaneNugent私の答えをupvotingし、正しいものとしてそれをマークすべてが私が必要なおかげです。あなたがここでコメントするだけの助けが必要な場合は、私の答えを修正します。 –
私がaddTarget部分で実行している唯一の問題です。私は** generate.addTargetを持っています(self、action:#select(self.someButtonClicked(_ :))、forControlEvents:.touchUpInside) ** "タイプ 'uiBarButtonItemの値に' addTarget 'というメンバーがありません" –