Forum Xamarin.iOS


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Programmatically hiding sections of a UITableView with static cells

RenzzsRenzzs NLMember ✭✭

I have a UITableView with three static sections in it, how can I programmatically hide the second section if a condition is true?

I found a article with a answer to my question but it is for objective-c and I don't know how to write it to MonoTouch...



  • RenzzsRenzzs NLMember ✭✭

    After a good lunch I had a break through and found the solution :P

    The code for the people who are interested (It hide's the first section if a condition is true):

    public override void ViewWillAppear (bool animated)
        base.ViewWillAppear (animated);
        x = true;
    int RowsInSection (UITableView tableView, int section)
        if (section == 0) {
                return 0;
        return 1; // Else has the first section one row
        return 4; // My second section has four rows
    float GetHeightForHeader (UITableView tableView, int section)
        if (section == 0 && x) {
            return 1;
        return 32;
    UIView GetViewForHeaderInSecion (UITableView tableview, int section)
        if (section == 0 && x) {
            return new UIView(View.Bounds);
        return null;
  • anjinlu.2497anjinlu.2497 CAMember ✭✭

    Hi Where did you add the above code ?

  • VishalGamjiVishalGamji USMember

    I think the code needs to be added in the TableViewSource delegate of your view controller that displays the table view.

Sign In or Register to comment.