Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 5    Views: 56

mjharris
Aspiring developer
Profile
Posts: 19
Reg: May 23, 2013
Boulder
3,440
06/14/13 11:37 AM (12 years ago)

Access titleText and descriptionText inside BTA_design_menu.m

I want to call the delegate method heightForRowAtIndexPath in order to dynamically create the cell height depending on the text inside of the cell. How can I access the the text for each row inside heightForRowAtIndexPath. My first thought was to just use: NSString *titleText = [BT_strings getJsonPropertyValue:screenData.jsonVars nameOfProperty:@"titleText" defaultValue:@""]; NSString *descriptionText = [BT_strings getJsonPropertyValue:screenData.jsonVars nameOfProperty:@"descriptionText" defaultValue:@""]; But it just uses the default value. I already know how to use sizeWithFont to get a CGSize of the title and description once I have the text, but how do I get the text in the first place??? Thanks, Max
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
06/14/13 11:48 AM (12 years ago)
You're close. Your code tries to get the titleText from the main screenData. You need to pull it from the childItem data. That data is included in the menuItems array. Use the row index number from the delegate method as the index number on the array. Each object in the array is a BT_item, which contains a jsonVars object inside it. So you would call [BT_strings getJsonPropertyValue:thisItem.jsonVars ...
 
mjharris
Aspiring developer
Profile
Posts: 19
Reg: May 23, 2013
Boulder
3,440
like
06/14/13 01:41 PM (12 years ago)
Thanks for the guidance. I changed it but it still is using the default values. If I change the default values, the row height changes work, but it's not picking up the text from the json. This is what I have: - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { BT_item *thisMenuItemData = [self.displayMenuItems objectAtIndex:indexPath.row]; NSString *titleText = [BT_strings getJsonPropertyValue:thisMenuItemData.jsonVars nameOfProperty:@"titleText" defaultValue:@""]; NSString *descriptionText = [BT_strings getJsonPropertyValue:thisMenuItemData.jsonVars nameOfProperty:@"descriptionText" defaultValue:@""]; UIFont *mytitleFont = [UIFont fontWithName:@"futura" size:20]; CGSize titleBoundingBox = [titleText sizeWithFont:mytitleFont]; UIFont *mydescriptionFont = [UIFont fontWithName:@"futura" size:14]; CGSize descriptionBoundingBox = [descriptionText sizeWithFont:mydescriptionFont constrainedToSize:CGSizeMake(320.f, MAXFLOAT) lineBreakMode:NSLineBreakByCharWrapping]; return 30 + titleBoundingBox.height + descriptionBoundingBox.height; } Thanks, Max
 
mjharris
Aspiring developer
Profile
Posts: 19
Reg: May 23, 2013
Boulder
3,440
like
06/14/13 02:03 PM (12 years ago)
Thanks for the guidance. I changed it but it still is using the default values. If I change the default values, the row height changes work, but it's not picking up the text from the json. This is what I have: - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { BT_item *thisMenuItemData = [self.displayMenuItems objectAtIndex:indexPath.row]; NSString *titleText = [BT_strings getJsonPropertyValue:thisMenuItemData.jsonVars nameOfProperty:@"titleText" defaultValue:@""]; NSString *descriptionText = [BT_strings getJsonPropertyValue:thisMenuItemData.jsonVars nameOfProperty:@"descriptionText" defaultValue:@""]; UIFont *mytitleFont = [UIFont fontWithName:@"futura" size:20]; CGSize titleBoundingBox = [titleText sizeWithFont:mytitleFont]; UIFont *mydescriptionFont = [UIFont fontWithName:@"futura" size:14]; CGSize descriptionBoundingBox = [descriptionText sizeWithFont:mydescriptionFont constrainedToSize:CGSizeMake(320.f, MAXFLOAT) lineBreakMode:NSLineBreakByCharWrapping]; return 30 + titleBoundingBox.height + descriptionBoundingBox.height; } Thanks, Max
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
06/14/13 08:19 PM (12 years ago)
Have you tried outputting the strings to NSLog just to make sure they're empty/default? Might be that this is getting called before menuItems is populated, but there should be a [tableView Reload] right after that happens, which should call this method again
 
mjharris
Aspiring developer
Profile
Posts: 19
Reg: May 23, 2013
Boulder
3,440
like
06/15/13 07:26 PM (12 years ago)
Thanks, It turns out I just needed to refresh even though I had recompiled. Now some of my screens have icons that I need toes sure the height of also. How can I access the height of the icons? Thanks, Max
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.