Reputation: 49
I have a very long string that i need to display in the first row of the table view. The string is like
"1|123|Try|Bank Of America|11/06/2007|20,000.00"
where | is the tokenizer.
Now I take the first token ie 1 and append String "\n", so that 123 is displayed in the next line of the row of table view, but I can just display 1 and 123 in the first row of the table view. I can't display the other values.
See the case is, the result string is the information of a transaction, similarly there are many more transactions that i will be displaying in the table view. But the rows in table are not big enough to display the entire information.
Upvotes: 0
Views: 563
Reputation: 491
To accomplish this the better way is to follow the customization of cell.You can increase the height of row using delegate method tableView:heightForRowAtIndexPath. (you need to return the height as return 55). Then you can add a label to cell and then add text to label with specifying the number of lines in label according to your requirement.
Upvotes: 1
Reputation: 43794
Been asked many times. See:
Upvotes: 0
Reputation: 1
You can try
[cell.textLabel setNumberOfLines:5];
This would in combination with the heightForRowAtIndexPath will give you what you are after.
Upvotes: 0
Reputation: 64428
You're going to have alter the height of the tableview cell depending on how many lines of data you want to display in each row. You will need to write a UITableViewDelegate's tableView:heightForRowAtIndexPath:
to return the correct row height for each row.
Calculating the row height will prove tricky if the number of lines of text changes each time or if the font size changes.
You might want to rethink your design. Tableviews are not intended to display a large amount of information. Instead, they are intended to display information that more or less fits on one line. You should consider a design that displays one line of information that will identify the record and then provide a detail view to show all the data in the record.
For example, in the contacts tableview, you have a tableview that shows the name of the contact and then a a detail view that shows the address, phone#, email etc.
Upvotes: 0
Reputation: 39376
Sounds like you are using the standard UITableViewCell. I'd recommend using a custom tableViewCell with a UILabel so you can control how the truncation is handled and how many lines you can have, etc. You still have to use @rein's suggestion of resizing the rows.
Upvotes: 0
Reputation: 33445
If I read your question correctly you want to increase the height of the row?
If so, you can use the delegate:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
Upvotes: 1