0

I am trying to add 2 labels in my table view cell. when in portrait mode the both labels overlap each other and in landscape mode it works fine.

I have also used auto-layout . Where i have to make changes to achieve the target.

- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *MyIdentifier = @"ProductTableViewCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];

    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier];
    }

    UILabel * productName= (UILabel *)[cell viewWithTag:101];


    //productName.text=[[productDetails objectAtIndex:indexPath.row]product_Name]; 
    // similar code for another label also 

    productName.lineBreakMode= NSLineBreakByWordWrapping;
    productName.numberOfLines=0;
    productName.text= @"asdfasdfsdzxcvzasdfaxv";
    [productName sizeToFit];

    return cell;
    }

Link for Issue for better description : http://f.talk.to/3afcd0c13764064184c01cc4

Thanks in advance :)

hgwhittle
  • 9,316
  • 6
  • 48
  • 60
vinay chorpa
  • 187
  • 3
  • 16
  • Are you trying to use a custom UITableViewCell? Where is the 'productName' UILabel coming from? – hgwhittle Aug 13 '13 at 15:18
  • yup i am trying to use custom UITableViewCell and in the storyboard on the product detail view controller i have a table view in which i have a cell and there i have used 2 labels. with tag 101 and 102 . – vinay chorpa Aug 13 '13 at 15:31
  • Where are you initializing and loading your custom cell? From the code above it seems that your tableCells are `UITableViewCellStyleDefault` cells. – hgwhittle Aug 13 '13 at 15:33
  • i have used : if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier]; } – vinay chorpa Aug 13 '13 at 15:40
  • Yes, but that will only give you a 'default' or 'out-of-the-box' cell, not a custom one. Check [this link](http://stackoverflow.com/questions/540345/how-do-you-load-custom-uitableviewcells-from-xib-files) for how to load custom UITableViewCells. – hgwhittle Aug 13 '13 at 15:45
  • Are you registering your custom UITableViewCell NIB somewhere else in your code? – hgwhittle Aug 13 '13 at 15:46
  • No i am not , Just put a label on the cell and given a tab to it and in the table view delegate check for the tag and populate the value . But i am able to get the value in my table view .. – vinay chorpa Aug 13 '13 at 15:49
  • have a look what i did :http://f.talk.to/3afcd0c13764090857ea64da – vinay chorpa Aug 13 '13 at 15:52
  • or you can suggest any other solution .. !! will be a great help ..:) – vinay chorpa Aug 13 '13 at 16:16
  • How you're loading your custom cell is just perplexing to me. But it digresses from your question, so if I figure something out about your overlapping issue I'll post an answer. – hgwhittle Aug 13 '13 at 16:22
  • do you need more code ? – vinay chorpa Aug 14 '13 at 07:46

0 Answers0