You're right. I totally missed your example below. Long day I guess. Thanks a 
lot, I'll give this a shot now!



From: Craig Dunn [mailto:[email protected]]
Sent: Monday, August 20, 2012 9:40 PM
To: Drew Greenwell
Cc: [email protected]
Subject: Re: [MonoTouch] Setting HighlightedTextColor when 
UITableViewCellSelectionStyle.None is used



well, that's what SelectedBackgroundView is for. my example shows setting it to 
a plain white view, which has the effect of removing the blue background 
highlight.



is there a reason that won't work in your case?



On Tue, Aug 21, 2012 at 11:38 AM, Drew Greenwell 
<[email protected]<mailto:[email protected]>> 
wrote:

Yeah I really just want the textlabel's Text color to change when the row is 
selected. Another TableViewCell class seemed like overkill. I guess I 
understand the logic behind UITableViewSelectionStyle.None disabling highlight 
color, but it seems like an unnecessary limitation. I guess I'm just going to 
have to subclass and remove the background highlight.



From: Craig Dunn [mailto:[email protected]<mailto:[email protected]>]
Sent: Monday, August 20, 2012 9:29 PM


To: Drew Greenwell
Cc: [email protected]<mailto:[email protected]>
Subject: Re: [MonoTouch] Setting HighlightedTextColor when 
UITableViewCellSelectionStyle.None is used



ah okay - so what is your goal? just to implement a custom 'selected' cell 
appearance?



You said: "Note: Setting SelectionStyle to anything but none makes the 
highlighted color show as expected when the row is selected"



Is that the behavior that you _want_? The expected effect of 
UITableViewCellSelection.None is that the cell has no distinct style when 
selected, so it makes sense that you need to set it to either Blue (default) or 
Grey for anything to "happen" (automatically) when a cell is selected.



if you want the on-tap behavior to be yellow text on a white background,

cell.TextLabel.TextColor = UIColor.Black;
cell.TextLabel.HighlightedTextColor = UIColor.Yellow;
//cell.SelectionStyle = UITableViewCellSelectionStyle.Blue; // or leave as 
default
cell.SelectedBackgroundView = new UIView(new 
System.Drawing.RectangleF(0,0,320,44)){BackgroundColor=UIColor.White};

or else - i'm misunderstanding what you are actually trying to accomplish?





p.s. this code should already be running on the main thread





On Tue, Aug 21, 2012 at 11:23 AM, Drew Greenwell 
<[email protected]<mailto:[email protected]>> 
wrote:

Sorry Craig, I didn't catch your second statement. The if/else modulus 
statement in my code generally has separate styles for the alternating row (I 
pass a CellStyle model that contains default and alternating styles). When I 
reduced the code, it would have been more appropriate for me to remove that if 
all together. Here is a more readable sample of my code.



public override UITableViewCell GetCell (UITableView tableView, NSIndexPath 
indexPath)

{

                // the row index

                int row = indexPath.Row;

                var dRow = Rows [row];

                // get a reusable cell instance and set the style

                var cell = tableView.DequeueReusableCell (TableCellIdentifier + 
dRow.ViewName + dRow.Text);

                if (cell == null) {

                                cell = InstantiateCell(dRow, 
UITableViewCellStyle.Subtitle, TableCellIdentifier);

                                cell.SelectionStyle =  
UITableViewCellSelectionStyle.None;

                                var label = cell.TextLabel;

                                label.TextColor = UIColor.Black;

                                label.HighlightedTextColor = UIColor.Yellow;

                }

}





From: 
[email protected]<mailto:[email protected]> 
[mailto:[email protected]<mailto:[email protected]>]
 On Behalf Of Drew Greenwell
Sent: Monday, August 20, 2012 9:07 PM
To: Craig Dunn


Cc: [email protected]<mailto:[email protected]>
Subject: Re: [MonoTouch] Setting HighlightedTextColor when 
UITableViewCellSelectionStyle.None is used



I actually initially thought about that and wrote this code below, but it also 
seems to have no effect. If I call cell.SetHighlighted(true, false); 
immediately after initializing the cell the highlight is on, but I need it to 
highlight only when the row is selected. I'm getting close to saying it can't 
be done without a custom cell, but that seems wrong.



public override NSIndexPath WillSelectRow (UITableView tableView, NSIndexPath 
indexPath)

{

                selectedRowIndex = indexPath;

                tableView.CellAt(indexPath).SetHighlighted(true, false);

                return indexPath;

}

public override void WillDeselectRow (UITableView tableView, NSIndexPath 
indexPath)

{

                tableView.CellAt(indexPath).SetHighlighted(false, false);

}



From: Craig Dunn [mailto:[email protected]]
Sent: Monday, August 20, 2012 7:42 PM
To: Drew Greenwell
Cc: [email protected]<mailto:[email protected]>
Subject: Re: [MonoTouch] Setting HighlightedTextColor when 
UITableViewCellSelectionStyle.None is used





_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to