Wrap in an iOSTable

I have an iOS Table and some of the entries are long and I need to do some sort of word wrap. I tried to add an end of line character but it does not work.

This works in an iOSLabel type field but not in a table:

Dim EOL As Text = Text.FromUnicodeCodepoint(10) msg = "Line 1" + EOL + "Line 2"

Once upon a time I built an iPhone app with Objective-C and I think the similar table did word wrap automatically.

Is there any solution for an iOSTable in XOJO?

AFAIK The only way to get around a lot of the problems currently found with iOSTable would be for someone to write a fully featured declares implementation or Xojo to fix there’s. Having looked into the work it would require I’m not willing to work on it for free, it would take a very long time to put together properly in declares. Maybe with a generalizable TableCell class or handle to the internal table cell so we could modify it with declares this would be possible, but until then you’ll probably have to stick to a single line somehow.

You may want to use a narrow font such as Avenir Next Condensed, or DIN Condensed.

Like this?

To get row heights for individual rows, you’d have to get deeper into subclassing stuff…

sample code:

[code] declare function NSClassFromString lib “Foundation” (name as CFStringRef) as ptr
Declare function indexPathForRowinSection lib “UIKit” selector “indexPathForRow:inSection:” (clss as ptr, row as integer, section as integer) as ptr
Declare function cellForRowAtIndexPath lib “UIKit” selector “cellForRowAtIndexPath:” (obj as ptr, path as ptr) as ptr
#if Target32Bit
declare sub setRowHeight lib “UIKit” selector “setRowHeight:” (obj as ptr, value as single)
#else
declare sub setRowHeight lib “UIKit” selector “setRowHeight:” (obj as ptr, value as Double)
#endif
declare sub setLineBreakMode lib “UIKit” selector “setLineBreakMode:” (obj as ptr, value as uinteger)
declare sub setNumberOfLines lib “UIKit” selector “setNumberOfLines:” (obj as ptr, value as uinteger)
declare Function detailTextLabel lib “UIKit” selector “detailTextLabel” (obj as ptr) as ptr
declare Function textLabel lib “UIKit” selector “textLabel” (obj as ptr) as ptr

table1.AddSection “”

dim d As iOSTableCellData
for i as integer=0 to 20
d=new iOSTableCellData
d.Text="this is a title that should not fit on one line - "+i.totext
d.DetailText=“this is some text that can not possibly fit on one line if I add enough text to make it too big for the line. And then maybe a third line?”
Table1.AddRow(0,d)

dim cell as ptr=cellForRowAtIndexPath(table1.Handle,indexPathForRowinSection(NSClassFromString("NSIndexPath"),Table1.RowCount(0)-1,0))
dim title As  ptr=textLabel(cell)
dim detail as ptr=detailTextLabel(cell)

setNumberOfLines(detail,0)
setLineBreakMode(detail,0)
setNumberOfLines(title,0)
setLineBreakMode(title,0)

next

setRowHeight((table1.Handle),110)

[/code]

I’m 99% sure that the view’s numberOfLines and lineBreakMode should not be touched when the view is reused… unless the Xojo framework does (it shouldn’t).

This shouldn’t affect the data, as the controller resets the data for a reused cell. I tested with 100 rows, each with different text and detail in the simulator, and didn’t see an issue…

Ok, I see what you’re saying. Yes, if you don’t want all rows to be multiline, you’ll need to subclass your own UITableViewDataSource.

Also, I should have added a “if cell<>nil then” to skip the title and detail stuff for proper form if cell isn’t visible.

This may also fail if your view resizes to expose more rows. You could access the visible rows’ cells to set the values though (using the visibleCells property).

My table should be static in terms of setNumberOfLines and setLineBreakMode. Thanks I will give it a try.

Now all I have to do is figure out a work around since I installed Xcode 7 and XOJO cannot find the simulator.

Does this stuff have to be so hard???

[quote=214073:@Mark Strickland]My table should be static in terms of setNumberOfLines and setLineBreakMode. Thanks I will give it a try.

Now all I have to do is figure out a work around since I installed Xcode 7 and XOJO cannot find the simulator.

Does this stuff have to be so hard???[/quote]

After I was forced to upgrade to 7 by El Capitan, I ended up installing Yosemite in a VM to be able to use 6.4.

Seems Apple loves to make it difficult for developers just as much as it likes making it easy on users :confused:

Somehow, I was able to install Xcode 6.4 and use it along side of the Xcode 7.1 Beta in El Capitan. Xojo was able to se the iOS 8.4 simulators.

Yes that definitely works. I renamed the Xcode 7 app bundle to “Xcode 7” and then reinstalled Xcode 6.4 alongside it as “Xcode” and Xojo 2015r2.4 is working fine for me too.

Jim,

COOL !!!

That seems to work for me. I noted the possible “gotcha’s” so I will be careful.

Now — Have you ever changed the font in in an iOS Table?

Thanks for the help.

The Wrap hint from Jim McKay above worked BUT I still did not have any control of the table fonts.

SO … I did more “tinkering” and managed to get this working from a post by Michel Bujardet.
https://forum.xojo.com/18152-ios-table-font
From his post …

[code] // http://developer.xojo.com/hsearch-iosbitmap
dim pic as new iOSBitmap(Table1.width, 40, 1, False)

// http://developer.xojo.com/iosfont
Dim Chalkduster As New iOSFont(“Chalkduster”, 18)

// http://developer.xojo.com/iosgraphics
pic.graphics.TextFont = Chalkduster
pic.graphics.FillColor = &cFF008000
pic.graphics.DrawTextLine(“Hello World”, 0, 20, -1, iOSTextAlignment.Center, False) // Centered

// http://developer.xojo.com/iostablecelldata
Dim mydata as new iOSTableCellData("","",pic.Image)

// http://developer.xojo.com/iostable$AddRow
Table1.AddSection("")
Dim cell As iOSTableCellData

cell = mydata
Table1.AddRow(0, cell)[/code]

I had to make one change because the solution in this post did NOT do any word wrap but it did give me the ability to do a custom font.

I switched DrawTextLine to DrawTextBlock and it did word wrap.

There also is a TextBlockSize function that appears to give you the height of a fixed width TextBlock (or vice versa). I am trying to see if I can vary the cell height in the iOS Table so smaller blocks with less text are not as tall and more visually pleasing.

I still need to work out the scale so I can handle standard and retina displays.

After a bit more fine tuning it appears that I can make a “pretty” iOS Table.

This is the kind of stuff that kills productivity.
Time to write the code to create a table … 15 minutes
Time to work out the details to make it “pretty” … 2 days and counting
Whewwwwwwww

Thanks to everybody for the help.

I put all of this here in case somebody else is trying to do the same.

Keep in mind the the “title” and “detail” ptr’s in my example are UILabels and you can use setFont to change them.

(untested code…)

[code]declare function NSClassFromString lib “Foundation” (name as CFStringRef) as ptr
declare sub setFont lib “UIKit” selector “setFont:” (obj as ptr, font as ptr)
declare function fontWithNamesize lib “UIKit” selector “fontWithName:size:” (obj as ptr, name as cfstringref, size as single)

dim font as ptr=fontWithNameSize(NSClassFromString(“UIFont”),“Arial”,20)
//not sure about font naming in uifont terms…
setFont(title,font)
[/code]

@Ulrich Bogun has done quite a bit of styling of buttons, etc. with colors and fonts in his iOSlib. Maybe he has font styling for iOSTables.

There’s indeed an AppleLabel object in iOSLib which gives you features like linebreakmode, numberoflines and font properties. Like Jim stated, handling the cells isn’t that easy for a longer table – you’d have to use the visiblecells property to change the design of your cell if it comes into view. That’s why I refrained from table manipulation, much like Jason.

Jim,

Not being so fluent in these things I get this error on compile when trying to use your “Untested Code” in your most recent reply.

Any thoughts?

Thanks.

Remove the NSClassFromString declare. It is already defined somewhere else in your project.

[quote=214287:@Mark Strickland]SO … I did more “tinkering” and managed to get this working from a post by Michel Bujardet.
https://forum.xojo.com/18152-ios-table-font
[/quote]

I am at the Xojo Conference at Scheveningen and did not have the time yesterday to do the search, but you find the way to have fonts in a table, and it seems that helped you with the current thread. Glad that was useful :slight_smile: