Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

rustywild

macrumors newbie
Original poster
Mar 9, 2011
20
0
Hi:

I have this line:
case 0: myList = [NSArray arrayWithObjects: @"cars",@"balls";

how can I put "cars" in bold font??, only "cars"


thanx
 
You would need to take care of that when you go to display those strings in your UI. So, how are you showing these values on the screen?

P.S. You may want to review that line for syntax errors. It should, at least, be generating warnings during compile.
 
It's always best to design your tableview data model so it contains the info needed for display so that there's a minimum of special-case code. Obviously a simple list of strings isn't enough to describe your data. You need a data object for each row. And in that data object you can put a font or you can put a flag that indicates bold/not bold. Then in your cellForRowAtIndexPath you check that value and make the label bold or not bold.

As a start I'd use an array of dictionaries. For each row dictionary I'd add the title and a boolean flag that indicates bold/not bold.
 
It's always best to design your tableview data model so it contains the info needed for display so that there's a minimum of special-case code. Obviously a simple list of strings isn't enough to describe your data. You need a data object for each row. And in that data object you can put a font or you can put a flag that indicates bold/not bold. Then in your cellForRowAtIndexPath you check that value and make the label bold or not bold.

As a start I'd use an array of dictionaries. For each row dictionary I'd add the title and a boolean flag that indicates bold/not bold.

Can you ut me q example??


thanx

Not sure what you mean by "make out". Please elaborate.

make out or highlight maybe
 
Last edited by a moderator:
Can you ut me q example??

Not quite sure what the translation of that is into English but I'll give you some psuedo code.

Code:
// viewDidLoad
// build the data model
NSMutableArray* rowArray = ;
self.rowArray = rowArray;

NSDictionary* rowDictionary = [NSDictionary dictionaryWithObjectsAndKeys: @"cars", kTitleKey, [NSNumber numberWithBool:YES], kBoldFontKey, nil];
[rowArray addObject:rowDictionary];

rowDictionary = [NSDictionary dictionaryWithObjectsAndKeys: @"balls", kTitleKey, [NSNumber numberWithBool:NO], kBoldFontKey, nil];
[rowArray addObject:rowDictionary];

// cellForRowAtIndexPath
// display the model object for this row
NSDictionary* rowDictionary = [self.rowArray objectAtIndex:row];
cell.titleLabel.text = [rowDictionary objectForKey:kTitleKey];
if ([[rowDictionary objectForKey:kBoldFontKey] boolValue])
  cell.titleLabel.font = some bold font;
else
  cell.titleLabel.font = some non-bold font;
 
Not quite sure what the translation of that is into English but I'll give you some psuedo code.

Code:
// viewDidLoad
// build the data model
NSMutableArray* rowArray = ;
self.rowArray = rowArray;

NSDictionary* rowDictionary = [NSDictionary dictionaryWithObjectsAndKeys: @"cars", kTitleKey, [NSNumber numberWithBool:YES], kBoldFontKey, nil];
[rowArray addObject:rowDictionary];

rowDictionary = [NSDictionary dictionaryWithObjectsAndKeys: @"balls", kTitleKey, [NSNumber numberWithBool:NO], kBoldFontKey, nil];
[rowArray addObject:rowDictionary];




// cellForRowAtIndexPath
// display the model object for this row
NSDictionary* rowDictionary = [self.rowArray objectAtIndex:row];
cell.titleLabel.text = [rowDictionary objectForKey:kTitleKey];
if ([[rowDictionary objectForKey:kBoldFontKey] boolValue])
  cell.titleLabel.font = some bold font;
else
  cell.titleLabel.font = some non-bold font;


A lot of thanx !!

i'm going to check.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.