-1

I am trying to building a to-do-list app. My StoryBoard consists of 2 view controller connected via push Segue. First ViewController is a table View Controller and second is a View Controller. Second View Controller consists a Title, description and date field, data is fetched from second View Controller and displayed in First View Controller. Data is received in form of an object say taskObject which has three attributes (Title, description and date) for three text fields.

I want to show have a cell Like Below:

Buy Notebook                                            (Title Text)

2 with both side rule pages, 1 with single side ruled   (Description Text)

27/07/2015                                              (Date Text)

I have already been through:

  1. Display multiple lines in a Table view's cell - IOS
  2. How to display multiple lines in a tableView cell

Just to be clear. Both are not my case.

I am trying to display like this :

cell.textLabel.text = [[self.allTask objectAtIndex:indexPath.row] titleText] ;
cell.detailTextLabel.numberOfLines = 0;
cell.detailTextLabel.Text = [self.allTask[indexPath.row] descriptionText];
cell.detailTextLabel.Text =[[self.allTask objectAtIndex:indexPath.row] dat

But it is not working, only last cell.textLabel.text's data is visible.

I did add:

cell.textLabel.numberOfLines = 0;
cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping;

But it is helpful ONLY if U want to show multiple lines from a single data source (NOT my case). In My situation have have to show three data from three different data attributes in three different lines within a cell.

I know it is possible through custom cells. Is their any other way to it ? Any Help Is Appreciated.

Community
  • 1
  • 1
Priyal
  • 879
  • 1
  • 9
  • 30
  • What's wrong with a custom cell? The stock cells are really just a convenience for use in simple situations. You obviously need a more complex cell, and you know what the answer is, so why avoid it? – Caleb Jul 27 '15 at 14:40
  • You need to see how to display multiple line in UILABEL ! – Vishal Sharma Jul 27 '15 at 14:43
  • @Caleb I am just a newbie in Objective-C and want to learn as new things and how similar thing can be done in varied ways. Just that ! – Priyal Jul 28 '15 at 06:43
  • @SharmaVishal I did goggle that ! – Priyal Jul 28 '15 at 06:44

2 Answers2

1

If you do

cell.textLabel.text = [[self.allTask objectAtIndex:indexPath.row] titleText] ;
cell.textLabel.text = [[self.allTask objectAtIndex:indexPath.row] descriptionText];
cell.textLabel.text = [[self.allTask objectAtIndex:indexPath.row] dateText];

you are effectively overwriting the textLabel each time. A standard UITableViewCell has another label, the detailTextLabel (if its style is not Default). But three labels is impossible without using custom cells. The best you can achieve is to use a multiline label, like this:

Task *task = (Task *)[self.allTask objectAtIndex:indexPath.row];
cell.textLabel.text = [task titleText];
cell.detailTextLabel.numberOfLines = 0; // 0 means 'no limit'
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@\n%@",
    [task descriptionText], [task dateText]];

You might need to adjust the tableview's rowHeight, though.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
  • I did try: cell.detailTextLabel.numberOfLines = 0; But adding the below code makes it working. cell.detailTextLabel.text = [NSString stringWithFormat:@"%@\n%@", [task descriptionText], [task dateText]]; Thanks ! – Priyal Jul 27 '15 at 14:42
  • You didn't mention `cell.detailTextLabel.numberOfLines = 0;` in your original version of the question - I'm glad you found that out yourself eventually. – Glorfindel Jul 27 '15 at 14:51
  • My Mistake ! But even with that your code : cell.detailTextLabel.text = [NSString stringWithFormat:@"%@\n%@", [task descriptionText], [task dateText]]; was required. Thanks ! – Priyal Jul 28 '15 at 06:39
0

You should create custom UITableViewCell and design it according to your needs.

This Article Here can be good place to get started

EDIT :-

It can be noticed from your code that, you are assigning the data to the same text label of your tableview cell, therefore only the latest string will be displayed on the cell.

The article linked in the answer effectively explains how you can create a custom UITableViewCell and design it as per our wants using storyboard.

Shailesh
  • 3,072
  • 3
  • 24
  • 33
  • You're on the right track, but so far this is almost a link-only answer. You could improve it quite a lot (and probably avoid some down votes) by summarizing the linked article, or just explaining briefly how to create a custom cell. – Caleb Jul 27 '15 at 14:37