Bernard
Bernard

Reputation: 4580

How to have multiple line in one cell without customising?

When I use NSLog it come in two lines but when I use it in the cell everything after \n will be vanished. I google this and there is wrap function which is deprecated.

Here is my code:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
                        object:(PFObject *)object {


    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
                                      reuseIdentifier:CellIdentifier];
    }
    NSString *eventName = [object objectForKey:@"name"];
    eventName = [eventName stringByAppendingString:dateString];
    //eventName = [NSString stringWithFormat: @"%@\\r\\n", eventName];
    eventName = [eventName stringByAppendingString:@"\n"];

    NSLog(@"%@",eventName);
    cell.textLabel.text = eventName;
    return cell;

}

Output:

ddd
03:00PM, 30 Aug - 03:00PM, 01 Sep

Here is what I have:

enter image description here

Upvotes: 0

Views: 106

Answers (1)

Rohit Kumar
Rohit Kumar

Reputation: 887

Use like this

textLabel.lineBreakMode = NSLineBreakByWordWrapping; 

textLabel.numberOfLines = 0; 

Here 0 represents infinite number of lines for a label. If you just want only 2 lines replace 0 with 2.

Upvotes: 4

Related Questions