好吧,我被卡住了。我有一个棘手的问题,让我的自定义表格视图单元格转换为'详细信息'我的Master-Detail应用程序的一部分,this other StackOverflow post修复它,调用prepareForSegue函数。我仍然没有得到我期望的结果,我发现了一个大问题:将单元格的属性传递给细节部分需要选择一个单元格,并且该帖子的代码会立即取消选择单元格在segue之前。看起来像一个简单的修复,但是当我删除该行时,程序在单击一个单元格时崩溃了。我真的不知道该怎么做(100%的iOS经验来自过去48小时),我希望有人可以提供帮助。
参与的代码:
<?php
date_default_timezone_set ('AMERICA/SANTIAGO');
$dbhost = getenv('OPENSHIFT_MYSQL_DB_HOST').':'.getenv('OPENSHIFT_MYSQL_DB_PORT');
$dbusername = getenv('OPENSHIFT_MYSQL_DB_USERNAME');
$dbpassword = getenv('OPENSHIFT_MYSQL_DB_PASSWORD');
$db_name = 'tuhoramedica';
$mysqlCon = mysqli_connect($dbhost, $dbusername, $dbpassword, "", $dbport) or die ("Disculpa, estamos teniendo algunas dificultades técnicas, por favor intentalo nuevamente más tarde. Gracias por tu comprensión.\n");
mysqli_select_db($mysqlCon, $db_name) or die("Disculpa, estamos teniendo algunas dificultades técnicas, por favor intentalo nuevamente más tarde. Gracias por tu comprensión.\n");
//Prevent SQL Injection
$usuario=mysqli_real_escape_string($mysqlCon, $_POST['user']);
$password=mysqli_real_escape_string($mysqlCon, $_POST['pass']);
stripslashes($user);
stripslashes($password);
$sql = "select * from usuarios where username='".$usuario."' and pswd='".$password."'";
$result=$mysqlCon->query($sql);
if ($result->num_rows === 1) {
session_start();
$row = $result->fetch_assoc();
//echo "Bienvenido " . $row["nombre"]." ".$row["apellido"];
$_SESSION["nr_usuario"] = $row["nr_usuario"];
$_SESSION["nombre_usuario"] = $row["nombre"];
$_SESSION["apellido_usuario"] = $row["apellido"];
$_SESSION["mail_usuario"] = $row["mail"];
$_SESSION["username_usuario"] = $row["username"];
$_SESSION["autentica"] = "SIP";
header("Location: http://tuhoramedica-chakana.rhcloud.com/filtro_horas.php");
exit;
} else {
echo "Lo sentimos, su usuario y/o contraseña no coinciden.";
}
$mysqlCon->close();
?>
错误(当我删除取消选择行时):
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "showDetail" {
if let indexPath = self.tableView.indexPathForSelectedRow {
let object = objects[indexPath.row]
let controller = (segue.destinationViewController as! UINavigationController).topViewController as! DetailViewController
controller.detailItem = object
controller.navigationItem.leftBarButtonItem = self.splitViewController?.displayModeButtonItem()
controller.navigationItem.leftItemsSupplementBackButton = true
}
}
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let cell = tableView.cellForRowAtIndexPath(indexPath)
tableView.deselectRowAtIndexPath(indexPath, animated: false) // What appears to be the problem
performSegueWithIdentifier("showDetail", sender: cell)
}
(在弹出的编辑器中:THREAD 1:EXC_BREAKPOINT)
感谢所有帮助。
答案 0 :(得分:0)
你尝试输入这样的代码:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let cell = tableView.cellForRowAtIndexPath(indexPath)
performSegueWithIdentifier("showDetail", sender: cell)
tableView.deselectRowAtIndexPath(indexPath, animated: false) // What appears to be the problem
}
但是我觉得你应该把你想要的对象发送到didSelectRowAtIndexpath
的下一个屏幕并将其传递给performSegue
,如下所示:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let object = objects[indexPath.row]
performSegueWithIdentifier("showDetail", sender: object)
tableView.deselectRowAtIndexPath(indexPath, animated: false)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "showDetail" {
if let object = sender as! "type of object" {
let controller = (segue.destinationViewController as! UINavigationController).topViewController as! DetailViewController
controller.detailItem = object
controller.navigationItem.leftBarButtonItem = self.splitViewController?.displayModeButtonItem()
controller.navigationItem.leftItemsSupplementBackButton = true
}
}
}
希望这有帮助!