これは、コード内でUITableViewCellを使用して、単一のCell内でTableview内のデータを 'Email'として持つようにUITableViewDatasourceのメソッドをオーバーライドするMyクラスです。 。これらのメソッドは実行されません。誰かこのisseuを解決するために私を助けてくれますか?UITableViewDataSourceメソッドを呼び出すことができません。デバッグ時にカーソルが取得されません
インポートUIKit
var operationViewFlag:Int!
クラスHomeCellView:UITableViewCellの {
@IBOutlet weak var btn_tablecell_Delete: UIButton!
@IBOutlet weak var btn_tablecell_Edit: UIButton!
@IBOutlet weak var lbl_tablecell_Email: UILabel!
}
クラスのViewController:のUIViewController、UITableViewDataSource、UITableViewDelegate {
@IBOutlet weak var TableView_Mainscreen: UITableView!
@IBOutlet weak var lbl_MainScreen_Title: UILabel!
@IBOutlet weak var btn_Mainscreen_Insert: UIButton!
var databasepath:String!
var arrayStudInfo:NSMutableArray!
// viewDidLoad
override func viewDidLoad()
{
operationViewFlag=1
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
lbl_MainScreen_Title.font = UIFont(name: "HelveticaNeue-Bold", size: 20)
btn_Mainscreen_Insert.layer.cornerRadius = 15
btn_Mainscreen_Insert.layer.borderWidth = 1
btn_Mainscreen_Insert.layer.borderColor = UIColor.brownColor().CGColor
// Variable Intialization
arrayStudInfo = NSMutableArray()
// Process for Creating Opening Database
let filemgr = NSFileManager.defaultManager()
let dirpath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
let docdir = dirpath[0] as String
databasepath = docdir.stringByAppendingString("StudentDataManipulation.sqlite");
if filemgr.fileExistsAtPath(databasepath as String)
{
let contactDB = FMDatabase(path: databasepath as String)
if contactDB == nil
{
print("Error: \(contactDB.lastErrorMessage())")
}
if contactDB.open()
{
let sql_stmt = "CREATE TABLE IF NOT EXISTS StudentData (Name TEXT, Phone TEXT, Email TEXT PRIMARY KEY NOT NULL, Comment TEXT)"
if !contactDB.executeStatements(sql_stmt)
{
print("Error: \(contactDB.lastErrorMessage())")
}
contactDB.close()
}
else
{
print("Error: \(contactDB.lastErrorMessage())")
}
}
}
//viewWillAppear
override func viewWillAppear(animated: Bool)
{
super.viewWillAppear(true)
listAllData()
}
//didReceiveMemoryWarning
override func didReceiveMemoryWarning()
{
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// Edit Method
@IBAction func btn_Edit_Clicked(sender: UIButton)
{
operationViewFlag=2
let updateView = self.storyboard?.instantiateViewControllerWithIdentifier("PerformOperation") as! PerformOperation
updateView.strEmail = arrayStudInfo[sender.tag]["Email"] as? String
print("Email to pass = \(updateView.strEmail)")
updateView.dictRecord = (arrayStudInfo[sender.tag] as! NSDictionary)
self.navigationController?.pushViewController(updateView, animated: true)
}
// Delete Method
@IBAction func btn_Delete_Clicked(sender: UIButton)
{
let contactDB = FMDatabase(path: databasepath as String)
let strDelete = arrayStudInfo[sender.tag]["Email"] as? String
if contactDB.open()
{
let deleteSQL = "DELETE FROM StudentData WHERE Email='\(strDelete!)'"
let result = contactDB.executeUpdate(deleteSQL, withArgumentsInArray: nil)
if !result
{
print("Error: \(contactDB.lastErrorMessage())")
}
else
{
print("Deleted Record.")
listAllData()
}
}
else
{
print("Error: \(contactDB.lastErrorMessage())")
}
contactDB.close()
}
// List All Data
func listAllData()
{
arrayStudInfo.removeAllObjects();
let contactDB = FMDatabase(path: databasepath as String)
if contactDB.open()
{
let filemgr = NSFileManager.defaultManager()
let dirpath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
let docdir = dirpath[0] as String
databasepath = docdir.stringByAppendingString("StudentDataManipulation.sqlite");
if filemgr.fileExistsAtPath(databasepath as String)
{
let contactDB = FMDatabase(path: databasepath as String)
if contactDB == nil
{
print("Error: \(contactDB.lastErrorMessage())")
}
if contactDB.open()
{
let sql_stmt = "CREATE TABLE IF NOT EXISTS StudentData (Name TEXT, Phone TEXT, Email TEXT PRIMARY KEY NOT NULL, Comment TEXT)"
if !contactDB.executeStatements(sql_stmt)
{
print("Error: \(contactDB.lastErrorMessage())")
}
let SelectQuery = "SELECT * FROM StudentData"
if let results:FMResultSet? = contactDB.executeQuery(SelectQuery, withArgumentsInArray: nil)
{
while results?.next() == true
{
let dictRecord = results?.resultDictionary()
arrayStudInfo.insertObject(dictRecord!, atIndex: arrayStudInfo.count)
print("\nRESULT : \(results?.resultDictionary())")
}
TableView_Mainscreen.reloadData()
}
else
{
print("Recored not found");
}
contactDB.close()
}
else
{
print("Error: \(contactDB.lastErrorMessage())")
}
}
contactDB.close()
}
else
{
print("Error: \(contactDB.lastErrorMessage())")
}
}
// TableView Methods
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return arrayStudInfo.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let Cell = tableView.dequeueReusableCellWithIdentifier("CellHome") as! HomeCellView
Cell.lbl_tablecell_Email.text! = arrayStudInfo[(indexPath.row)]["Email"] as! String
print("Your Email : \(Cell.lbl_tablecell_Email.text!)")
Cell.btn_tablecell_Edit.tag=indexPath.row
Cell.btn_tablecell_Delete.tag=indexPath.row
Cell.btn_tablecell_Edit.layer.cornerRadius = 10
Cell.btn_tablecell_Delete.layer.cornerRadius = 10
// btn_Delete_Clicked
Cell.btn_tablecell_Edit.addTarget(self, action: #selector(ViewController.btn_Edit_Clicked(_:)), forControlEvents: UIControlEvents.TouchUpInside)
Cell.btn_tablecell_Delete.addTarget(self, action: #selector(ViewController.btn_Delete_Clicked(_:)), forControlEvents: UIControlEvents.TouchUpInside)
return Cell
}
}
'TableView_Mainscreen'の' dataSource'行を見つけることができません。 – OOPer
ありがとうございました。 –