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]]
Sent: Monday, August 20, 2012 9:29 PM
To: Drew Greenwell
Cc: [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



What about



cell.Highlighted = true; // no animation

or
cell.SetHighlighted(true,false); // optional animation



? I'm not really sure what effect you are trying to accomplish with this 
code... if it is just to have different colors on every second row, why not 
just set the TextColor directly inside your if-else?





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

Hey all, I've got a UITableViewCell that I want to change the 
HighlightedTextColor. Setting the HighlightedtextColor property only seems to 
work when UITableViewCellSelectonStyle is set to something other than None. Do 
I have to subclass UITableViewCell to get this to apply or am I just missing 
something?



Here's a trimmed down version of my GetCell method. Note: Setting 
SelectionStyle to anything but none makes the highlighted color show as 
expected when the row is selected



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);

                                                                
if(indexPath.Row % 2 == 0){

                                                                                
// setting this to anything but None shows the highlighted text color

                                                                                
cell.SelectionStyle = UITableViewCellSelectionStyle.None;

                                                                                
var label = cell.TextLabel;

                                                                                
label.TextColor = UIColor.Black;

                                                                                
label.HighlightedTextColor = UIColor.Yellow;                                    
                                                                               
}else{

                                                                                
// setting this to anything but None shows the highlighted text color

                                                                                
cell.SelectionStyle = UITableViewCellSelectionStyle.None;

                                                                                
var label = cell.TextLabel;

                                                                                
label.TextColor = UIColor.Black;

                                                                                
label.HighlightedTextColor = UIColor.Yellow;

                                                                }

                                                }



Thanks in advance for any insight.



__________ Information from ESET NOD32 Antivirus, version of virus signature 
database 7403 (20120820) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com


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





__________ Information from ESET NOD32 Antivirus, version of virus signature 
database 7403 (20120820) __________



The message was checked by ESET NOD32 Antivirus.



http://www.eset.com



__________ Information from ESET NOD32 Antivirus, version of virus signature 
database 7403 (20120820) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com


__________ Information from ESET NOD32 Antivirus, version of virus signature 
database 7403 (20120820) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com



__________ Information from ESET NOD32 Antivirus, version of virus signature 
database 7403 (20120820) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com





__________ Information from ESET NOD32 Antivirus, version of virus signature 
database 7403 (20120820) __________



The message was checked by ESET NOD32 Antivirus.



http://www.eset.com

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

Reply via email to