Francesco
Francesco

Reputation: 5153

MonoTouch UITableViewController and TableFooterView

I'm trying to develop a small iPhone application using MonoDevelop (v2.8) and MonoTouch (v4.2.2).

My home screen is represented by a UITableViewController which use a UITableView for presentation. I want to fill the UITableView.TableFooterView (which is a UIView object) with some other controls (two labels and two buttons).

To do this I have created a "subview" called SearchView, which is represented by a UIViewController and use a simple UIView for presentation. I assign this view as footer view of the tableview.

public partial class HomeScreen : UITableViewController
{    
    public override void ViewDidLoad()
    {
        base.ViewDidLoad();

        SearchViewController searchViewController = new SearchViewController();
        this.TableView.TableFooterView = searchViewController.View;

    }
}

Is this right?

It is right to assume that usaually you create a view (UIView) and consume it by a UIViewController ?

Upvotes: 2

Views: 895

Answers (2)

Robert Kozak
Robert Kozak

Reputation: 2033

In your UITableViewDataSource you can override public virtual UIView GetViewForFooter(UITableView tableView, int sectionIndex)

    public override UIView GetViewForFooter(UITableView tableView, int sectionIndex)
    {
        // Write a method to get the proper Section via the sectionIndex
        var section = GetSection(sectionIndex);
        if (section != null)
        {
            if (section.FooterView == null && !string.IsNullOrEmpty(section.FooterText))
            {
                // Create your FooterView here 
                section.FooterView = CreateFooterView(tableView, section.FooterText);
            }

            return section.FooterView;
        }

        return null;
    }

As of iOS 5 you will also need to override

public virtual float GetHeightForFooter(UITableView tableView, int sectionIndex)

and return the height of the FooterView

Upvotes: 0

ICoder
ICoder

Reputation: 1347

- (void)loadView {
[super loadView];
sBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0,0,320,30)];
sBar.delegate = self;
[self.view addSubview:sBar];

you can add subviews like this ,sbar is the search bar,u can also add any controllers like button ,labels ,textview,textfield in it.

Upvotes: 1

Related Questions