-
Notifications
You must be signed in to change notification settings - Fork 0
/
StoryboardExtensions.cs
159 lines (138 loc) · 9.98 KB
/
StoryboardExtensions.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
using Foundation;
using UIKit;
namespace NomadCode.iOS
{
public static class StoryboardExtensions
{
/// <summary>
/// Instantiate a new instance of a UIViewController subclass from the specified storyboard.
/// This override assumes storyboardIdentifier of the UIViewController subclass is the same as
/// the Name of the Type.
/// </summary>
/// <param name="storyboard">The UIStoryboard containing the UIViewController subclass.</param>
/// <typeparam name="T">The Type of the UIViewController subclass to instantiate and return.</typeparam>
public static T Instantiate<T> (this UIStoryboard storyboard)
where T : UIViewController
=> storyboard.InstantiateViewController (typeof (T).Name) as T;
/// <summary>
/// Instantiate a new instance of a UIViewController subclass from the specified storyboard.
/// </summary>
/// <param name="storyboard">The UIStoryboard containing the UIViewController subclass.</param>
/// <param name="storyboardIdentifier">The UIViewController subclass's Storyboard identifier.</param>
/// <typeparam name="T">The Type of the UIViewController subclass to instantiate and return.</typeparam>
public static T Instantiate<T> (this UIStoryboard storyboard, string storyboardIdentifier)
where T : UIViewController
=> storyboard.InstantiateViewController (storyboardIdentifier) as T;
/// <summary>
/// Instantiate a new instance of a UIViewController subclass from the specified storyboard.
/// </summary>
/// <param name="storyboard">The UIStoryboard containing the UIViewController subclass.</param>
/// <param name="storyboardIdentifier">The UIViewController subclass's Storyboard identifier.</param>
public static UIViewController Instantiate (this UIStoryboard storyboard, string storyboardIdentifier)
=> storyboard.InstantiateViewController (storyboardIdentifier) as UIViewController;
/// <summary>
/// Dequeues a reusable UITableViewCell subclass using specified UITableView and NSIndexPath.
/// Usually called in the UITableViewDataSource (or UITableViewController) GetCell override.
/// This override assumes that the reuseIdentifier of the UITableViewCell subclass is the same as
/// the Name of the Type.
/// </summary>
/// <param name="tableView">The UITableView from which to dequeue the cell</param>
/// <param name="indexPath">The cell's NSIndexPath</param>
/// <typeparam name="T">The Type of the UITableViewCell subclass to dequeue and return.</typeparam>
public static T Dequeue<T> (this UITableView tableView, NSIndexPath indexPath)
where T : UITableViewCell
=> tableView.DequeueReusableCell (typeof (T).Name, indexPath) as T;
/// <summary>
/// Dequeues a reusable UITableViewCell subclass using specified UITableView and NSIndexPath.
/// Usually called in the UITableViewDataSource (or UITableViewController) GetCell override.
/// </summary>
/// <param name="tableView">The UITableView from which to dequeue the cell.</param>
/// <param name="reuseIdentifier">The reuseIdentifier of the UITableViewCell subclass to return.</param>
/// <param name="indexPath">The cell's NSIndexPath.</param>
/// <typeparam name="T">The Type of the UITableViewCell subclass to dequeue and return.</typeparam>
public static T Dequeue<T> (this UITableView tableView, string reuseIdentifier, NSIndexPath indexPath)
where T : UITableViewCell
=> tableView.DequeueReusableCell (reuseIdentifier, indexPath) as T;
/// <summary>
/// Dequeues a reusable UICollectionViewCell subclass using specified UICollectionView and NSIndexPath.
/// Usually called in the UICollectionViewDataSource (or UICollectionViewController) GetCell override.
/// This override assumes that the reuseIdentifier of the UICollectionViewCell subclass is the same as
/// the Name of the Type.
/// </summary>
/// <param name="collectionView">The UICollectionView from which to dequeue the cell.</param>
/// <param name="indexPath">The cell's NSIndexPath.</param>
/// <typeparam name="T">The Type of the UICollectionViewCell subclass to dequeue and return.</typeparam>
public static T Dequeue<T> (this UICollectionView collectionView, NSIndexPath indexPath)
where T : UICollectionViewCell
=> collectionView.DequeueReusableCell (typeof (T).Name, indexPath) as T;
/// <summary>
/// Dequeues a reusable UICollectionViewCell subclass using specified UICollectionView and NSIndexPath.
/// Usually called in the UICollectionViewDataSource (or UICollectionViewController) GetCell override.
/// </summary>
/// <param name="collectionView">The UICollectionView from which to dequeue the cell.</param>
/// <param name="reuseIdentifier">The reuseIdentifier of the UICollectionViewCell subclass to return.</param>
/// <param name="indexPath">The cell's NSIndexPath.</param>
/// <typeparam name="T">The Type of the UICollectionViewCell subclass to dequeue and return.</typeparam>
public static T Dequeue<T> (this UICollectionView collectionView, string reuseIdentifier, NSIndexPath indexPath)
where T : UICollectionViewCell
=> collectionView.DequeueReusableCell (reuseIdentifier, indexPath) as T;
/// <summary>
/// Dequeues a reusable UICollectionReusableView subclass using specified UICollectionView, elementKind and NSIndexPath.
/// Usually called in the UICollectionViewDataSource (or UICollectionViewController) GetViewForSupplementaryElement override.
/// This override assumes that the reuseIdentifier of the UICollectionReusableView subclass is the same as
/// the Name of the Type.
/// </summary>
/// <param name="collectionView">The UICollectionView from which to dequeue the reusable view</param>
/// <param name="elementKind">The kind of supplementary view to provide.
/// The value of this string is defined by the layout object that supports the supplementary view.</param>
/// <param name="indexPath">The index path that specifies the location of the new supplementary view.</param>
/// <typeparam name="T">The Type of the UICollectionReusableView subclass to dequeue and return.</typeparam>
public static T Dequeue<T> (this UICollectionView collectionView, NSString elementKind, NSIndexPath indexPath)
where T : UICollectionReusableView
=> collectionView.DequeueReusableSupplementaryView (elementKind, typeof (T).Name, indexPath) as T;
/// <summary>
/// Dequeues a reusable UICollectionReusableView subclass using specified UICollectionView, elementKind and NSIndexPath.
/// Usually called in the UICollectionViewDataSource (or UICollectionViewController) GetViewForSupplementaryElement override.
/// This override assumes that the reuseIdentifier of the UICollectionReusableView subclass is the same as
/// the Name of the Type.
/// </summary>
/// <param name="collectionView">The UICollectionView from which to dequeue the reusable view</param>
/// <param name="elementKind">The kind of supplementary view to provide.
/// The value of this string is defined by the layout object that supports the supplementary view.</param>
/// <param name="reuseIdentifier">The reuseIdentifier of the UICollectionReusableView subclass to return.</param>
/// <param name="indexPath">The index path that specifies the location of the new supplementary view.</param>
/// <typeparam name="T">The Type of the UICollectionReusableView subclass to dequeue and return.</typeparam>
public static T Dequeue<T> (this UICollectionView collectionView, NSString elementKind, string reuseIdentifier, NSIndexPath indexPath)
where T : UICollectionReusableView
=> collectionView.DequeueReusableSupplementaryView (elementKind, reuseIdentifier, indexPath) as T;
/// <summary>
/// Dequeues a reusable UICollectionReusableView subclass using specified UICollectionView, elementKind and NSIndexPath.
/// Usually called in the UICollectionViewDataSource (or UICollectionViewController) GetViewForSupplementaryElement override.
/// This override assumes that the reuseIdentifier of the UICollectionReusableView subclass is the same as
/// the Name of the Type.
/// </summary>
/// <param name="collectionView">The UICollectionView from which to dequeue the reusable view</param>
/// <param name="elementKind">The kind of supplementary view to provide.
/// The value of this string is defined by the layout object that supports the supplementary view.</param>
/// <param name="indexPath">The index path that specifies the location of the new supplementary view.</param>
/// <typeparam name="T">The Type of the UICollectionReusableView subclass to dequeue and return.</typeparam>
public static T Dequeue<T> (this UICollectionView collectionView, UICollectionElementKindSection elementKind, NSIndexPath indexPath)
where T : UICollectionReusableView
=> collectionView.DequeueReusableSupplementaryView (elementKind, typeof (T).Name, indexPath) as T;
/// <summary>
/// Dequeues a reusable UICollectionReusableView subclass using specified UICollectionView, elementKind and NSIndexPath.
/// Usually called in the UICollectionViewDataSource (or UICollectionViewController) GetViewForSupplementaryElement override.
/// This override assumes that the reuseIdentifier of the UICollectionReusableView subclass is the same as
/// the Name of the Type.
/// </summary>
/// <param name="collectionView">The UICollectionView from which to dequeue the reusable view</param>
/// <param name="elementKind">The kind of supplementary view to provide.
/// The value of this string is defined by the layout object that supports the supplementary view.</param>
/// <param name="reuseIdentifier">The reuseIdentifier of the UICollectionReusableView subclass to return.</param>
/// <param name="indexPath">The index path that specifies the location of the new supplementary view.</param>
/// <typeparam name="T">The Type of the UICollectionReusableView subclass to dequeue and return.</typeparam>
public static T Dequeue<T> (this UICollectionView collectionView, UICollectionElementKindSection elementKind, string reuseIdentifier, NSIndexPath indexPath)
where T : UICollectionReusableView
=> collectionView.DequeueReusableSupplementaryView (elementKind, reuseIdentifier, indexPath) as T;
}
}