Hello Akshay,
We have Xamarin iOS examples app that is located in the [installation folder (or zip archive on Mac) of the controls] > Examples > iOS. You can take a look at the ListView examples to see how you can use custom cells.
Here is a code snippet that demonstrates how to register a custom cell:
public
class
SomeViewController : UIViewController
{
TKListView listView;
TKDataSource dataSource;
public
override
void
ViewDidLoad()
{
base
.ViewDidLoad();
listView =
new
TKListView();
listView.RegisterClassForCell(
new
ObjCRuntime.Class(
typeof
(CustomCellView)), CustomCellView.Key);
NSMutableDictionary mails =
new
NSMutableDictionary();
for
(
int
i = 0; i < 20; i++)
{
mails.Add(
new
NSString(
"item "
+ i),
new
NSString(
"detail "
+ i));
}
dataSource =
new
TKDataSource();
this
.dataSource.ItemSource = mails;
this
.dataSource.Settings.ListView.InitCell(
delegate
(TKListView listView, NSIndexPath indexPath, TKListViewCell cell, NSObject item)
{
cell.TextLabel.Text = item
as
NSString;
});
this
.dataSource.Settings.ListView.CreateCell(
delegate
(TKListView listView, NSIndexPath indexPath, NSObject item)
{
var cell = listView.DequeueReusableCell(CustomCellView.Key, indexPath)
as
asdasd;
if
(cell.SwipeBackgroundView.Subviews.Length == 0)
{
// add views
}
return
cell;
});
this
.listView.Frame =
this
.View.Bounds;
this
.listView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
this
.listView.WeakDataSource =
this
.dataSource;
this
.listView.AllowsCellSwipe =
true
;
this
.listView.CellSwipeLimits =
new
UIEdgeInsets(0, 60, 0, 60);
this
.listView.CellSwipeTreshold = 30;
((TKListViewLinearLayout)
this
.listView.Layout).ItemSize =
new
CGSize(100, 80);
this
.View.AddSubview(
this
.listView);
}
}
First, you only need to register a cell type once. Second, the listView.RegisterNib(...) method that you use does not call the base constructor where the SwipeBackgroundView is initialized. If you use the listView.RegisterClassForCell(...) method, it works fine. Please, let us know if this approach works for you. If not, could you please send us a sample project that reproduces the issue?
I look forward to your reply.
Regards,
Rosy Topchiyska
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the
Telerik Feedback Portal and vote to affect the priority of the items