Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Indexed TableViews not displaying after upgrade to MT 4.0

After upgrading to MT 4.0, my TableViews that previously were displaying indexes on the right hand border are no longer working. The tableview still displays in sections and works properly, but the index is not displaying.

I have these three methods defined in my UITableViewSource, and all three appear to be working:

public override string[] SectionIndexTitles(UITableView tableView)

public override int SectionFor(UITableView tableView, string Title, int atIndex)

public override string TitleForHeader(UITableView tableView, int section)

Is anyone else having this problem? Is this a bug with MT 4.0?

like image 359
Jason Avatar asked Apr 11 '11 20:04

Jason


2 Answers

This is a known bug.

It appears that UITableView is not retaining the returned array, you can use the following to work around this issue while we investigate it further:

NSArray array;

[Export ("sectionIndexTitlesForTableView:")]
public NSArray SectionTitles (UITableView tableview)
{   
    if (array == null) {
        string[] titles = new string[RowsInSection(tableview, 0)];
        for (int index = 0; index < titles.Length; index++)
            titles[index] = index.ToString();

        array = NSArray.FromStrings (titles);
    }

    return array;
}
like image 52
Jason Avatar answered Oct 13 '22 20:10

Jason


This was showing to me just numbers (index for each item of the section 0 (like A letter of the index), so I found that must change this to:

        NSArray array;

        [Export ("sectionIndexTitlesForTableView:")]
        public NSArray SectionTitles (UITableView tableview)
        {                   
            if (array == null)
            {           
                array = NSArray.FromStrings (SectionIndexTitles(tableview));
            }

            return array;
        }
like image 30
Karl Heinz Brehme Arredondo Avatar answered Oct 13 '22 19:10

Karl Heinz Brehme Arredondo