-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
MvxSimpleTableViewSource.cs
58 lines (49 loc) · 2.39 KB
/
MvxSimpleTableViewSource.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MS-PL license.
// See the LICENSE file in the project root for more information.
using System;
using Foundation;
using Microsoft.Extensions.Logging;
using MvvmCross.Logging;
using ObjCRuntime;
using UIKit;
namespace MvvmCross.Platforms.Ios.Binding.Views
{
public class MvxSimpleTableViewSource : MvxTableViewSource
{
private readonly NSString _cellIdentifier;
private readonly MvxIosMajorVersionChecker _iosVersion6Checker = new MvxIosMajorVersionChecker(6);
protected virtual NSString CellIdentifier => _cellIdentifier;
public MvxSimpleTableViewSource(NativeHandle handle)
: base(handle)
{
MvxLogHost.Default?.LogWarning("MvxSimpleTableViewSource NativeHandle constructor used - we expect this only to be called during memory leak debugging - see https://github.com/MvvmCross/MvvmCross/pull/467");
}
public MvxSimpleTableViewSource(UITableView tableView, string nibName, string cellIdentifier = null,
NSBundle bundle = null, bool registerNibForCellReuse = true)
: base(tableView)
{
// if no cellIdentifier supplied, then use the nibName as cellId
cellIdentifier = cellIdentifier ?? nibName;
_cellIdentifier = new NSString(cellIdentifier);
if (registerNibForCellReuse)
{
tableView.RegisterNibForCellReuse(UINib.FromName(nibName, bundle ?? NSBundle.MainBundle), cellIdentifier);
}
}
public MvxSimpleTableViewSource(UITableView tableView, Type cellType, string cellIdentifier = null)
: base(tableView)
{
// if no cellIdentifier supplied, then use the cell type name as cellId
cellIdentifier = cellIdentifier ?? cellType.Name;
_cellIdentifier = new NSString(cellIdentifier);
tableView.RegisterClassForCellReuse(cellType, _cellIdentifier);
}
protected override UITableViewCell GetOrCreateCellFor(UITableView tableView, NSIndexPath indexPath, object item)
{
if (_iosVersion6Checker.IsVersionOrHigher)
return tableView.DequeueReusableCell(CellIdentifier, indexPath);
return tableView.DequeueReusableCell(CellIdentifier);
}
}
}