I wanted the same thing, but the only way I found to do it was to manually set 
the selected element's background color whenever a new selection is made. So I 
ended up with the following code. Just get the element from the index path and 
call SelectElement() from DvcOnOnSelection().

Element selectedElement = null;

private void SelectElement(StyledStringElement element)
{
        if (element != selectedElement)
        {
                if (selectedElement != null)
                {
                        selectedElement.TextColor = UIColor.Black;
                        selectedElement.BackgroundColor = UIColor.White;
                }
                selectedElement = element;
                selectedElement.TextColor = UIColor.White;
                selectedElement.BackgroundColor = UIColor.Blue;
                ReloadData();
        }
}

-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of Guido Van Hoecke
Sent: Monday, June 04, 2012 6:49 AM
To: Craig Dunn
Cc: René Ruppert; [email protected]
Subject: Re: [MonoTouch] How to keep selected (element)row highlighted

Craig,

Unfortunately, MWC does not use Monotouch.Dialog: it uses its own
UITableView which gives a finer control over things.

My Master is a DialogViewController, which is also available on the
iPhone with some minor conditional stuff, mostly to differentaite
between the iPhone and iPad paradigm.

I can highlight the entry at NSIndexParth.FromRowSection(0,0) at initial
loading time, but fail to keep the selection highlighted whenever an
entry is tapped.

Here's what I've got to handle this:

* in the Dialog Constructor:

if (AppDelegate.IsPad)
        Dvc.OnSelection += DvcOnOnSelection;

* and the DvcOnSelection method:

private void DvcOnOnSelection(NSIndexPath nsIndexPath)
{
        Dvc.TableView.SelectRow(
                Dvc.TableView.IndexPathForSelectedRow,
                true,
                UITableViewScrollPosition.None);
}

This method is called whenever a row is tapped, but it does not
preserve nor force the selection color.

Any ideas to preserve the selected color in Monotouch.Dialog?
It would be a pity if I had to recode the existing iPhone controller as
a lower level TableViewController on the Ipad...

Thanks in advance,

Guivho.




On 3 June 2012 23:58, Craig Dunn <[email protected]> wrote:
> The MWC sample does that - both for the master list (landscape view) and
> also the mini 'speaker list' for sessions that you can see in this
> screenshot.
> https://raw.github.com/xamarin/mobile-samples/master/MWC/Screenshots/iOS/Sessions_iPad.PNG
>
> the relevant pieces of code are :
> * in the SpeakersTableViewSource.cs, we DON'T deselect, so the blue
> highlight will remain
>
> if (AppDelegate.IsPhone) tableView.DeselectRow (indexPath, true);
>
>
>
> * in SessionView.cs we set the selection to a particular row when loading
>
> if (AppDelegate.IsPad) {
>
> // set the highlight for whatever speaker is showing in the other column
> (only iPad, obviously)
>
>    if (speakerTable.IndexPathForSelectedRow == null)
>
>       speakerTable.SelectRow (NSIndexPath.FromRowSection (0,0), true,
> UITableViewScrollPosition.Top);
>
>    else
>
>       speakerTable.SelectRow (speakerTable.IndexPathForSelectedRow, true,
> UITableViewScrollPosition.Top);
>
>
> HTH
> craig
>
>
> On Sun, Jun 3, 2012 at 10:38 PM, Guido Van Hoecke <[email protected]> wrote:
>>
>> Hi,
>>
>> I'm working at a universal app where I use the wonderfull
>> MTSplitViewController when ran on the iPad
>> (Thank you René).
>>
>> Both Master and Detail panes use DialogViewControllers
>> (Thank you Miguel).
>>
>> Selecting an element on the Master creates and pushes the corresponding
>> DialogController onto the UINavigationController associated with the
>> Detail pane.
>>
>> This interaction works like a charm!
>>
>> When I tap an element in the Master pane, the blue selection bar fades
>> out, which is the normal expected behaviour. However, for a Master pane
>> it would be desirable that this selection color would not diappear,
>> leaving a clear trace of the selected option that corresponds to the
>> current Detail pane content, as a kind of the 'Active menu choice'.
>>
>> I dare hope that this can be easily achieved, but I've stackoverflowed
>> and googled around without success.
>>
>> Any ideas or suggestions?
>>
>> Thanks in advance,
>>
>>
>> Guido
>>
>> --
>> You will be surprised by a loud noise.
>>
>> http://vanhoecke.org ... and go2 places!
>> _______________________________________________
>> MonoTouch mailing list
>> [email protected]
>> http://lists.ximian.com/mailman/listinfo/monotouch
>
>
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to