Skip to content

Instantly share code, notes, and snippets.

@nirinchev
Last active August 29, 2015 14:15
Show Gist options
  • Save nirinchev/d9db62291e2d0812d995 to your computer and use it in GitHub Desktop.
Save nirinchev/d9db62291e2d0812d995 to your computer and use it in GitHub Desktop.
An extension method to dequeue a cell for use in UITableViewController.GetCell
public static T DequeueReusableCell<T> (this UITableView tableView) where T : UITableViewCell
{
var identifier = typeof(T).Name;
var cell = tableView.DequeueReusableCell (identifier);
if (cell == null)
{
// Nib with the class name MUST exist in the name bundle
var nib = UINib.FromName (identifier, NSBundle.MainBundle);
tableView.RegisterNibForCellReuse (nib, identifier);
cell = tableView.DequeueReusableCell (identifier);
}
return (T)cell;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment