Я получаю это сообщение об ошибке при запуске моего приложения:
Foundation.MonoTouchException: создано исключение Objective-C. Имя: NSInvalidArgumentException Причина: -[TableSource initWithCoder:]: нераспознанный селектор отправлен экземпляру 0x796e6fa0
Я уже искал в гугле, но не нашел решения.
О приложении: Приложение имеет UITableView с некоторыми пользовательскими ячейками. UITableView находится в обычном «представлении». В обычном «представлении» также есть кнопка, эта кнопка должна (при касании) добавлять пользовательскую ячейку в UITableView.
UITableView имеет имя «tableView» и свойства класса «TableSource». Кнопка имеет имя "btn01" и в свойствах как класс "ViewController".
Пользовательские ячейки имеют «идентификатор повторного использования» «Cell01Reuse», «Cell02Reuse» и т. д. И класс «Testclass» (который не существует в виде файла).
Контроллер представления (база, на которой все включено) имеет класс «ViewController».
У меня есть два класса с кодом. Во-первых, это «Контроллер просмотра»:
using System;
using UIKit;
using Foundation;
using System.Collections.Generic;
namespace myapp
{
public partial class ViewController : UIViewController
{
public ViewController(IntPtr handle) : base(handle)
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
// Perform any additional setup after loading the view, typically from a nib.
//UITableView _table;
//_table = new UITableView
//{
// Frame = new CoreGraphics.CGRect(0, View.Bounds.Height * 0.03, View.Bounds.Width, View.Bounds.Height * 0.80),
// Source = new TableSource(null)
//};
//_table.SeparatorStyle = UITableViewCellSeparatorStyle.None;
//View.AddSubview(_table);
TableSource TS = new TableSource();
btn01.TouchUpInside += (sender, e) =>
{
TS.updateTableView();
string cell01 = "Cell01Reuse";
TS.tableItems.Add(cell01);
};
}
public override void DidReceiveMemoryWarning()
{
base.DidReceiveMemoryWarning();
// Release any cached data, images, etc that aren't in use.
}
}
}
Во-вторых, "TableSource":
using System;
using System.Collections.Generic;
using System.Text;
using Foundation;
using UIKit;
namespace myapp
{
public partial class TableSource : UITableViewSource
{
//string[] tableItems;
public List<string> tableItems = new List<string>();
public static string cellIdentifier = "TableCell";
//public TableSource(string[] items)
//{
// tableItems = items;
//}
public TableSource()
{
}
public override nint RowsInSection(UITableView tableview, nint section)
{
return 0;
}
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
UITableViewCell cell = tableView.DequeueReusableCell(cellIdentifier);
if (cell == null)
{
cell = new UITableViewCell(UITableViewCellStyle.Default, cellIdentifier);
}
cell.TextLabel.Text = tableItems[indexPath.Row];
tableItems.Add(Convert.ToString(cell));
return cell;
}
public override nint NumberOfSections(UITableView tableView)
{
return base.NumberOfSections(tableView);
}
public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
{
new UIAlertView("Alert", "You touched: " + tableItems[indexPath.Row], null, "OK", null).Show();
tableView.DeselectRow(indexPath, true);
}
public void updateTableView()
{
tableView.updateTableView();
}
}
}