Skip to content

Instantly share code, notes, and snippets.

@felipeslongo
Created March 22, 2019 21:24
Show Gist options
  • Save felipeslongo/82cf162f8382b54c499a713996c5b34a to your computer and use it in GitHub Desktop.
Save felipeslongo/82cf162f8382b54c499a713996c5b34a to your computer and use it in GitHub Desktop.
Xamarin.IOS extension that gets the parent UITableView from the UITableViewCell
namespace UIKit
{
/// <summary>
/// Xamarin.IOS extension that gets the parent <see cref="UITableView"/> from the <see cref="UITableViewCell"/>
/// </summary>
/// <seealso cref="https://stackoverflow.com/questions/15711645/how-to-get-uitableview-from-uitableviewcell"/>
public static class UITableViewCell_GetTableView
{
/// <summary>
/// Gets the parent <see cref="UITableView"/>
/// </summary>
/// <param name="this"></param>
/// <returns><see cref="UITableView"/> instance or null ir detached</returns>
public static UITableView GetTableView(this UITableViewCell @this)
{
var superView = @this.Superview;
while (superView != null && !(superView is UITableView))
superView = superView.Superview;
return (UITableView)superView;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment