- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在构建一个相当简单的应用程序,但遇到了问题。现在,我的应用程序有一个主屏幕和一个表格 View ,每个单元格中都有一个事件的名称。数据从我的数据库正常加载到我的单元格,当您单击单元格时,它会将您带到一个新的 View Controller 。我想将特定信息放入与我的事件名称相对应的每个标签中。例如,如果当我单击单元格时显示 STEM Leadership Confrence,我希望三个标签具有匹配的文本:日期、分值和时间范围。任何帮助将不胜感激,谢谢。 (Swift 4 和 Firebase RT 数据库)
import UIKit
import Firebase
var refa: DatabaseReference!
class TableViewController: UITableViewController {
var posts = [eventStruct]()
@IBOutlet weak var Tableview: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
refa = Database.database().reference()
loadNews()
Tableview?.delegate = self
Tableview?.dataSource = self
}
struct eventStruct {
let Name: String!
let date: String!
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
self.performSegue(withIdentifier: "TableToSignUp", sender: self)
}
func loadNews() {
refa.child("Events").queryOrderedByKey().observe(.childAdded, with: { (snapshot) in
if let valueDictionary = snapshot.value as? [AnyHashable:String]
{
let Name = valueDictionary["Name"]
let date = valueDictionary["date"]
self.posts.insert(eventStruct(Name: Name, date: date), at: 0)
self.Tableview.reloadData()
}
})
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return posts.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = Tableview.dequeueReusableCell(withIdentifier: "AllEventsCell", for: indexPath)
//let label1 = cell.viewWithTag(1) as? UILabel
cell.textLabel?.text = posts[indexPath.row].Name
//let cell2 = Tableview.dequeueReusableCell(withIdentifier: "AllEventsCell", for: indexPath)
return cell
}
}
ViewController 类:UIViewController、GIDSignInUIDelegate {
@IBOutlet weak var Nav: UINavigationBar!
@IBOutlet weak var NumOfParticipants: UITextField!
@IBOutlet weak var TimeFrame: UITextField!
@IBOutlet weak var EndDate: UITextField!
@IBOutlet weak var Points: UITextField!
@IBOutlet weak var Create: UIButton!
@IBOutlet weak var ViewAll: UIButton!
@IBOutlet weak var CreateEventButton: UIButton!
@IBOutlet weak var ViewMyEventsButton: UIButton!
@IBOutlet weak var Name: UITextField!
var ref: DatabaseReference?
override func viewDidLoad() {
super.viewDidLoad()
CreateEventButton?.layer.cornerRadius = 30
CreateEventButton?.clipsToBounds = true
Create?.layer.cornerRadius = 30
Create?.clipsToBounds = true
ViewMyEventsButton?.layer.cornerRadius = 30
ViewMyEventsButton?.clipsToBounds = true
ViewAll?.layer.cornerRadius = 30
ViewAll?.clipsToBounds = true
GIDSignIn.sharedInstance().uiDelegate = self
GIDSignIn.sharedInstance().signIn()
// Do any additional setup after loading the view.
}
@IBAction func CreateEvent(_ sender: Any) {
let text: String = (Name.text)!
let date: String = (EndDate.text)!
let point: String = (Points.text)!
let timeFrame: String = (TimeFrame.text)!
let numOfpar: String = (NumOfParticipants.text)!
ref = Database.database().reference()
let now = Date()
let formatter = DateFormatter()
formatter.timeZone = TimeZone.current
formatter.dateFormat = "yyyy-MM-dd"
let dateString = formatter.string(from: now)
let newUserData = ["Name": text, "date": date, "Point Value": point, "Time Frame": timeFrame, "Volunteers Needed": numOfpar, "Date Created": dateString] as [String: Any]
ref?.child("Events").childByAutoId().updateChildValues(newUserData)
}
//,; ["Amount of Points": point];["Date End": date]
}
AppDelegate 类:UIResponder、UIApplicationDelegate、GIDSignInDelegate{
let userDefault = UserDefaults()
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error?) {
if let error = error{
print(error.localizedDescription)
return
}else{
let userId = user.userID // For client-side use only!
let idToken = user.authentication.idToken // Safe to send to the server
let fullName = user.profile.name
let givenName = user.profile.givenName
let familyName = user.profile.familyName
let email = user.profile.email
let str = email
let me = str?.count
let int = (me!-9)
let secondInt = (me!-8)
let XStr = str?.dropFirst(secondInt)
let NewStr = str?.dropFirst(int)
guard let authentication = user.authentication else{return}
let crendential = GoogleAuthProvider.credential(withIDToken: authentication.idToken, accessToken: authentication.accessToken)
Auth.auth().signInAndRetrieveData(with: crendential) {(result, error)in
if error == nil {
self.userDefault.set(true, forKey: "usersignedIn")
self.userDefault.synchronize()
if(NewStr == "gmail.com"){
self.window?.rootViewController?.performSegue(withIdentifier: "TeacherSegue", sender: self)
}
else if(XStr == "aisd.net"){
self.window?.rootViewController?.performSegue(withIdentifier: "TeacherSegue", sender: self)
}
}else {
//self.window?.rootViewController?.performSegue(withIdentifier: "Wegue", sender: self)
print(error?.localizedDescription ?? "me")
}
}
}
}
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
// Use Firebase library to configure APIs
FirebaseApp.configure()
GIDSignIn.sharedInstance().clientID = FirebaseApp.app()?.options.clientID
GIDSignIn.sharedInstance().delegate = self
return true
}
@available(iOS 9.0, *)
func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any])
-> Bool {
return GIDSignIn.sharedInstance().handle(url,
sourceApplication:options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
annotation: [:])
}
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 application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
return GIDSignIn.sharedInstance().handle(url,
sourceApplication: sourceApplication,
annotation: annotation)
}
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:.
}
}
Events-
-LdK2x1kNMB6fBw0Oorn
-LdLPGh-_SXIjM7DhjDV
-LdPVnBYQtAtSOyZM1IR-
Date: "2019-04-28"
Name:"STEM Leadership Confrence"
Point Value: "12"
Time Frame: "3-4"
最佳答案
您需要将信息传递给下一个UIViewController
。
首先,将您需要的所有信息放入 eventStruct
中,并在 Firebase 回调中更新结构初始化。
struct EventStruct {
...
var timeFrame: String!
var points: Int!
}
如果您使用 Storyboard,则需要实现 tableView(_:didSelectRowAt:)
方法并使用 segue
执行到下一个 View 的转换。此链接将帮助您向 segue
Xcode, where to assign the segue identifier 添加标识符
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let detailToSend: EventStruct = posts[indexPath.row]
performSegue(withIdentifier: "showDetailSegue", sender: detailToSend)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let vc = segue.destination as? ViewController, let detailToSend = sender as? EventStruct {
vc.detail = detailToSend
}
}
如果您使用 View 代码,则只需要 tableView(_:didSelectRowAt:)
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let detailToSend: EventStruct = posts[indexPath.row]
let vc = ViewController()
vc.detail = detailToSend
self.present(vc, animated: true, completion: nil)
}
之后,在 ViewController
的 viewDidLoad()
中将信息分配给标签。
TimeFrame.text = detail.timeFrame
另一个建议,看看快速最佳实践,例如 https://github.com/raywenderlich/swift-style-guide或者在您的项目中使用 SwiftLint。
关于ios - 我需要从我的 firebase 数据库中获取数据并将其放入标签中,但数据需要与我的 tableView 单元格标题相对应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55896704/
我附上了一个我尝试使用 html/css 实现的示例(如果您看不到图像:名字和姓氏,然后第二行是职位描述)。我希望所有文本(两行)在一个 div 中强制对齐(左和右),但我不确定这是否可能。我尝试了一
我想使两个 h1 元素成为 div 上的标题/页眉。所以每个都在特定的 div 之上。 Youtube Achievements
我想让每个 EditText 对象都有自己的标题,就像 Pure Android 指南中那样 (screenshot) 这个东西有原生支持吗?我想他们也可能会使用带有部分的 ListView ,但这对
是否可以像 UITableView headerView 一样创建 UICollectionView 标题 View ?我的意思是整个集合 View 的标题 View ,而不是每个部分的重复 View
我一直在遵循有关排版的 Google 官方 Material 设计指南 (http://www.google.com/design/spec/style/typography.html),但我发现它们
我目前正在尝试找到可以帮助我从视频文件中提取元数据或信息的 python 库,例如 [ mp4, Mkv, Avi, WebM, mpg ] 格式为例。 我主要从视频文件中提取的主要数据是 [标题、描
你好, 这是我正在尝试做的: 将每个缩略图的内容(img + 标题)居中。我的 img 必须是 span3,标题必须是 span4。 这是我的问题: 我可以获取内容中心,或者标题 float 在 im
我有一个带有导航栏的应用程序,可以从一个 View Controller 导航到下一个 View Controller 。在某些模拟器和设备上导航到下一个 View Controller 时,后退按钮
我遇到了一些非常酷的 t-sql,可以从一个 t-sql 查询中的选定行生成一个逗号分隔的列值列表: SELECT @MyList = ISNULL(@MyList,'') + Title + ',
请确保将 HTML heading 标签只用于标题。不要仅仅是为了生成粗体或的文本而使用标题。 搜索引擎使用标题为您的网页的结构和内容编制索引。 因为用户可以通过标题来快速浏览您的网页,所以用标
我正在使用 wkhtmltopdf 将 html 转换为 pdf。 我想在每个页面中添加标题,但它只显示在第一页(目录)中。 我使用的命令是 "C:\Program Files\wkhtmltopdf
如何使用 ggplot2 显示观察的方向(标题)?有没有办法调整shape=17 (三角形)以便它“指向”下一次观察? 示例代码 library(ggplot2) dat % pivot_wide
我尝试在 cocoa 应用程序中显示/隐藏标题栏。我使用以下代码: if ([window styleMask]==NSResizableWindowMask) { [wind
我有这样的 HTML 标题 http://s1.postimg.org/4ebyk3qwv/image.png 当我编写这段代码时: document.getElementById("TL85_1_
我叫麦克。谢谢你的帮助。 在Wordpress中,我们已经设计了我们的网站,以便在Facebook调试器中og数据尽可能接近youtube。尽管如此,在Facebook上共享视频的方式还是不同的。尽管
从 web 应用程序的客户端,我点击了服务器端路由,它只是第三方 API 的包装器。使用分派(dispatch),我试图让服务器端请求返回 exact header 和第三方 API 对客户端 AJA
从 web 应用程序的客户端,我点击了服务器端路由,它只是第三方 API 的包装器。使用分派(dispatch),我试图让服务器端请求返回 exact header 和第三方 API 对客户端 AJA
我是 SAPUI5 的新手,在导航、侧边栏和标题方面遇到一些问题。我想开发一个带有标题和侧边栏的应用程序。我为此使用“ToolPage”。每个页面都包含工具页,如下所示:
我最近在为客户做的项目中被介绍给Go。他们已经建立了代码库,需要进行一些更改。 我注意到所有的方法,结构等等都有一些奇怪的类似于标题的注释,如下所示: // SomeType ... type Som
我创建了一个采用整个屏幕布局的标题布局(xml 文件)... 我还创建了一个 listView 并将此 header_layout 添加到 listView 中: LayoutInflater inf
我是一名优秀的程序员,十分优秀!