如何在表格视图上显示复选标记?



我想做一个验证开/关按钮,以显示学生是否通过验证。在"AddStudentViewController"中打开开关后,在"StudentDataBaViewController"的表格列表中特定学生行的右侧将显示一个复选标记。我可以知道该怎么做吗?

**附加信息:

1(StudentDataBaViewContoller(应用程序的第一页(是一个TableViewController 2(AddStudentViewController(应用程序的第二页(是一个普通的视图控制器

两者都与名为"StuSegue"的推送Segue连接

下面附上了我的 2 视图控制器的代码:


"StudentDataBaViewController"的代码:

using Foundation;
using System;
using UIKit;
using SQLite;
using System.Collections.Generic;
using System.IO;
namespace One
{
public partial class StudentDataBaViewController : UITableViewController
{
private string pathToDatabase;
private List<Student> students;
public StudentDataBaViewController (IntPtr handle) : base (handle)
{
students = new List<Student>();
}
/*public override void PrepareForSegue(UIStoryboardSegue segue, NSObject sender)
{
if (segue.Identifier == "StuSegue")
{ // set in Storyboard
var navctlr = segue.DestinationViewController as AddStudentViewController;
if (navctlr != null)
{
var source = TableView.Source as StudentDataBaViewController;
var rowPath = TableView.IndexPathForSelectedRow;
var item = source.GetItem(rowPath.Row);
navctlr.SetTask(this, item); // to be defined on the TaskDetailViewController
}
}
} 
*/
//connect to student_da.db database file and create a table named Student
public override void ViewDidLoad()
{
base.ViewDidLoad();
//path of the database
var documentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
pathToDatabase = Path.Combine(documentsFolder, "student_db.db");
//connect database and create table
using (var connection = new SQLite.SQLiteConnection(pathToDatabase))
{
connection.CreateTable<Student>();
}
}
//used to relaod or update new elements entered on the list
public override void ViewDidAppear(bool animated)
{
base.ViewDidAppear(animated);
students = new List<Student>();
using (var connection = new SQLite.SQLiteConnection(pathToDatabase))
{
var query = connection.Table<Student>();
foreach (Student student in query)
{
students.Add(student);
TableView.ReloadData();
}
}
}
public override nint RowsInSection(UITableView tableView, nint section)
{
return students.Count;
}
//make elements to be display on the database list
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
UITableViewCell cell = tableView.DequeueReusableCell("student");
var data = students[indexPath.Row];
cell.TextLabel.Text = data.StudentName;
cell.DetailTextLabel.Text = data.StudentId;
return cell;
}
public override bool CanEditRow(UITableView tableView, NSIndexPath indexPath)
{
return true;
}
public override void CommitEditingStyle(UITableView tableView, UITableViewCellEditingStyle editingStyle, Foundation.NSIndexPath indexPath)
{
switch (editingStyle)
{
case UITableViewCellEditingStyle.Delete:
// remove the item from the underlying data source
students.RemoveAt(indexPath.Row);
// delete the row from the table
tableView.DeleteRows(new NSIndexPath[] { indexPath }, UITableViewRowAnimation.Fade);

break;
case UITableViewCellEditingStyle.None:
Console.WriteLine("CommitEditingStyle:None called");
break;
}
}
}
public class Student
{
[PrimaryKey]
public string StudentId
{
get;
set;
}
public string StudentName
{
get;
set;
}
public string StudentPassword
{
get;
set;
}
public bool StudentAttendence
{
get;
set;
}
}
}  

"AddStudentViewController"的代码:

using Foundation;
using System;
using System.IO;
using UIKit;
namespace One
{
public partial class AddStudentViewController : UIViewController
{
private string pathToDatabase;

//used to access same database to grab data for display
protected AddStudentViewController (IntPtr handle) : base (handle)
{
// Note: this .ctor should not contain any initialization logic.
var documentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
pathToDatabase = Path.Combine(documentsFolder, "student_db.db");
}
// create a function for save button
public override void ViewDidLoad()
{
base.ViewDidLoad();
// Perform any additional setup after loading the view, typically from a nib.
saveStudent.Clicked += SaveButton_Clicked;
}
public override void DidReceiveMemoryWarning()
{
base.DidReceiveMemoryWarning();
// Release any cached data, images, etc that aren't in use.
}
//create connection with database and make handler for save button and insert the element into database
void SaveButton_Clicked(object sender, EventArgs e)
{
using (var connection = new SQLite.SQLiteConnection(pathToDatabase))
{
connection.Insert(new Student() { StudentName = AddStuNameTxt.Text, StudentId = AddStuIdTxt.Text, StudentPassword = AddStuPassTxt.Text, StudentAttendence =true  });
new UIAlertView("Updated !", "Student successfully created", null, "OK", null).Show();
}
//navigate page back to database list
NavigationController.PopToRootViewController(true);
}

}
}

根据我的理解,您希望在"AddStudentViewController"中打开开关后,拒绝"StudentDataBaViewController"中的UI。 可以使用委托在两个控制器之间发送消息。

相关内容

  • 没有找到相关文章

最新更新