У меня есть uitableview с кнопкой, чтобы очистить линию. Но после удаления записи базы данных uitableview я хочу перезагрузить, но получаю сообщение об ошибке (System.NullReferenceException). Я думаю, что это происходит потому, что класс наследует (UITableViewSource), а не (UIViewController). Как это решить?Загрузка uitableview
Ниже приведен код класса, отвечающий за загрузку uitableview.
Большое спасибо
public class FonteTabelaExercicios : UITableViewSource
{
private ExercicioBanco banco = new ExercicioBanco();
private List<Exercicio> exercicosBanco;
private string cellIdentifier = "TableCell";
UIButton btn;
private NavController nav = new NavController();
public FonteTabelaExercicios (List<Exercicio> banco)
{
exercicosBanco = banco;
}
public override nint RowsInSection (UITableView tableview, nint section)
{
if (exercicosBanco != null) {
return exercicosBanco.Count;
} else {
return 0;
}
}
public override UITableViewCell GetCell (UITableView tableView, Foundation.NSIndexPath indexPath)
{
UITableViewCell cell = tableView.DequeueReusableCell (cellIdentifier);
if (cell == null)
cell = new UITableViewCell (UITableViewCellStyle.Default, cellIdentifier);
cell.TextLabel.Text = exercicosBanco [indexPath.Row].Nome + " - " + exercicosBanco [indexPath.Row].Quantidade;
btn = new UIButton (new CGRect (0, 0, 70, 30));
btn.SetTitle("Apagar", UIControlState.Normal);
btn.SetTitleColor (UIColor.White,UIControlState.Normal);
btn.BackgroundColor = UIColor.Blue;
cell.AccessoryView = btn;
btn.TouchUpInside += (sender, e) => {
int result = 0;
UIAlertView alert = new UIAlertView(
"Confirmação",
"Deseja apagar este dado?",
null,
NSBundle.MainBundle.LocalizedString ("Cancelar", "Cancel"),
NSBundle.MainBundle.LocalizedString ("OK", "OK")
);
alert.Show();
alert.Clicked += (object sender2, UIButtonEventArgs es) => {
if (es.ButtonIndex == 0)
{
Console.WriteLine("Não");
}
else
{
result = banco.ExecutaDelete(exercicosBanco [indexPath.Row]);
if (result > 0) {
//Loads listaRecorsViewController with uitableview
listaRecorsViewController record = (listaRecorsViewController)nav.Storyboard.InstantiateViewController("listaRecords");
nav.PushViewController(record, false);
}
}
};
};
return cell;
}
}
Какая линия вызывает исключение? – Giorgi
Вы хотите перезагрузить этот Uitableview или вставить новый ViewController? – Sreeraj