I want to create a custom table cell for my iPhone application by Monodevelop and xcode 4 based on monotouch. I found this articles:
http://slodge.blogspot.co.uk/2013/01/uitableviewcell-using-xib-editor.html
by this two article I create a class like this:
[Register("ListingCell")]
public partial class ListingCell : UITableViewCell
{
public ListingCell () : base()
{
}
public ListingCell (IntPtr handle) : base(handle)
{
}
public void BindDataToCell(DrivedProperty _property)
{
LocatoinLbl.Text = _property .LocationString ;
}
public void AddImageToCell(UIImage _image){
ListingThumbnail .Image = _image ;
}
}
and the I designed my UITableViewCell
and defined outlets. Then in my GetCell
method I used codes like this:
public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
{
ListingCell cell;
cell = (ListingCell) tableView.DequeueReusableCell (identifier ) ;
if (cell == null) {
cell = new ListingCell ();
var views = NSBundle.MainBundle.LoadNib("ListingCell", cell, null);
cell = Runtime.GetNSObject( views.ValueAt(0) ) as ListingCell;
}
var item = Controller.Items [indexPath.Row];
cell.Tag = indexPath.Row;
cell .BindDataToCell (item );
cell.AddImageToCell ( item .Image);
return cell;
}
Now, Application builds well, but when I run it debuger gets error with this line:
var views = NSBundle.MainBundle.LoadNib("ListingCell", cell, null);
and say:
MonoTouch.Foundation.MonoTouchException: Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: Could not load NIB in bundle: 'NSBundle </Users/john/Library/Application Support/iPhone Simulator/6.0/Applications/08FFAA89-4AC4-490D-9C1A-4DE4CBC6EBB7/Realtyna_iPhone_Project.app> (loaded)' with name 'ListingCell'
Realy I don't know for what is this. When I delete it. The application make arror with cell object in my ListingCell
class. I have run many searchs in the internet but didn'nt find any solutions. Do any body have any idea about this?
I found that it is possible to create the custom cell programmatically. and it will work but the problem is that creating difficult cells programmatically in run time is to difficult. It is simple that we create this cells by excode but idon't know why it not works :-S