Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Need some help with table views...

$
0
0

My first question is in regards to customizing headers in a table view. The problem I'm having is that when I declare GetViewForHeader, it's overwriting the header names (or erasing them) I'm generating from TitleForHeader. Here are the two methods:

public override UIView GetViewForHeader (UITableView tableView, int section)
{
  UILabel headerLabel = new UILabel ();
  headerLabel.TextColor = UIColor.Black;
  headerLabel.Font = UIFont.BoldSystemFontOfSize (18.0f);
  headerLabel.Frame = new RectangleF (15.0f, 0.0f, 500.0f, 20.0f);

  return headerLabel;
}

public override string TitleForHeader (UITableView tableView, int section)
{
  return data [section].QuestionName;
}

My second question relates to multiple selections within a table view. I currently have a table that is grouped into various sections, and I want to be able to select an item from each section, but only one item per section (similar behavior to a radio button I guess). I've set AllowMultipleSelections = true, which of course allows me to select multiple rows in each section which is not what I'm going for. I tried this code but received a null reference exception:

public override NSIndexPath WillSelectRow (UITableView tableView, NSIndexPath indexPath)
{
  foreach (var selectedIndex in tableView.IndexPathsForSelectedRows) 
  {
    if (selectedIndex.Section == indexPath.Section) 
        tableView.DeselectRow (selectedIndex, false);
  }

  return indexPath;

}

I don't even think this is probably the best or most efficient way to approach this so any help or guidance would be much appreciated. Thank you.


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>