タグのミスなのか、バージョンなのかわからないエラー文が出てしまいました。
swift
1import UIKit 2 3class RecordViewController: UIViewController ,UITableViewDataSource, 4UITableViewDelegate{ 5 6 var aD:AppDelegate! 7 8 override func viewDidLoad() { 9 super.viewDidLoad() 10 11 // Do any additional setup after loading the view. 12 aD = UIApplication.shared.delegate as? AppDelegate 13 } 14 15 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> 16 Int { 17 return aD.records.count 18 } 19 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 20 var cell = tableView.dequeueReusableCell( withIdentifier: "Cell") 21 22 var nameLabel = cell?.viewWithTag(1) as! UILabel 23 nameLabel.text = aD.records[indexPath.row][0] as? String 24 25 var genderLabel = cell?.viewWithTag(2) as! UILabel 26 genderLabel.text = aD.records[indexPath.row][1] as? String 27 28 var scoreLabel = cell?.viewWithTag(3) as! UILabel 29 let score:Int = aD.records[indexPath.row][2] as! Int 30 scoreLabel.text = "(score)%" 31 32 return cell ?? 33 } 34 35 36
上記の
nameLabel.text = aD.records[indexPath.row][0] as? String
let score:Int = aD.records[indexPath.row][2] as! Int
genderLabel.text = aD.records[indexPath.row][1] as? String
の部分に「Ambiguous use of 'subscript(_:)'」というエラー文が出てしまいます。
また、最終行に「Expected expression after operator」というエラー文が発生してしまいました。
試したこと
main.boardのtagに該当の数字を入れているかチェックした。
nilなのかわからない部分を!と?どちらも試してみた。
他の方の参考サイトもみたのですが、わからなかったので質問させていただきました。
雑な質問で申し訳ないのですが、ご教授いただきたいです????♂️
足りない情報などありましたら、おっしゃっていただけるとありがたいです!
swift
1import UIKit 2 3@UIApplicationMain 4class AppDelegate: UIResponder, UIApplicationDelegate { 5 6 var window: UIWindow? 7 var name: String = "" 8 var gender: String = "" 9 var score: Int = 0 10 var records: [AnyObject] = [] 11 12 13 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 14 // Override point for customization after application launch. 15 return true 16 } 17 18 func applicationWillResignActive(_ application: UIApplication) { 19 // 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. 20 // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 21 } 22 23 func applicationDidEnterBackground(_ application: UIApplication) { 24 // 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. 25 // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 26 } 27 28 func applicationWillEnterForeground(_ application: UIApplication) { 29 // 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. 30 } 31 32 func applicationDidBecomeActive(_ application: UIApplication) { 33 // 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. 34 } 35 36 func applicationWillTerminate(_ application: UIApplication) { 37 // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 38 } 39 40 41} 42 43
回答2件
あなたの回答
tips
プレビュー