iPhone: UITableView with cells of varying heights

  • I am pulling in an RSS feed, and each item has it's own summary of a varying
    amount of text. I am using a table and presently setting the height of each
    row the same to allow for the most text. This looks awful as some items have
    a lot of empty space for it's row.

    Is it possible to have a UILabel where I set numberOfLines = 0, set the
    width, and have the height of the label expand vertically to contain all of
    the text, and then use it's height to help determine the height the cell
    itself needs to be? The result would be a UITableView with rows of varying
    heights, perfectly framing each row's content.

    I was using a UIWebView to display the summary since it came with tons of
    html tags in it, but I've since just stripped all of the tags out of each
    item's summary.

    Thanks,
    Eric
  • Calculate label height with [NSString sizeWithFont:ForWidth:LineBreakMode:]. sizeWithFont:forWidth:lineBreakMode:

    Assign cell row heights with [UITableViewDelegate tableView:heightForRowAtIndexPath:] – tableView:heightForRowAtIndexPath:

    Luke

    On Jan 14, 2010, at 6:46 AM, Eric E. Dolecki wrote:

    > I am pulling in an RSS feed, and each item has it's own summary of a varying
    > amount of text. I am using a table and presently setting the height of each
    > row the same to allow for the most text. This looks awful as some items have
    > a lot of empty space for it's row.
    >
    > Is it possible to have a UILabel where I set numberOfLines = 0, set the
    > width, and have the height of the label expand vertically to contain all of
    > the text, and then use it's height to help determine the height the cell
    > itself needs to be? The result would be a UITableView with rows of varying
    > heights, perfectly framing each row's content.
    >
    > I was using a UIWebView to display the summary since it came with tons of
    > html tags in it, but I've since just stripped all of the tags out of each
    > item's summary.
    >
    > Thanks,
    > Eric
  • Hmm, those were supposed to be links at the end of the lines.

    http://developer.apple.com/iphone/library/documentation/UIKit/Reference/NSS
    tring_UIKit_Additions/Reference/Reference.html#//apple_ref/doc/uid/TP400068
    93-CH3-SW7


    http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIT
    ableViewDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UI
    TableViewDelegate/tableView:heightForRowAtIndexPath
    :

    Luke

    On Jan 14, 2010, at 6:56 AM, Luke the Hiesterman wrote:

    > Calculate label height with [NSString sizeWithFont:ForWidth:LineBreakMode:]. sizeWithFont:forWidth:lineBreakMode:
    >
    > Assign cell row heights with [UITableViewDelegate tableView:heightForRowAtIndexPath:] – tableView:heightForRowAtIndexPath:
    >
    > Luke
    >
    > On Jan 14, 2010, at 6:46 AM, Eric E. Dolecki wrote:
    >
    >> I am pulling in an RSS feed, and each item has it's own summary of a varying
    >> amount of text. I am using a table and presently setting the height of each
    >> row the same to allow for the most text. This looks awful as some items have
    >> a lot of empty space for it's row.
    >>
    >> Is it possible to have a UILabel where I set numberOfLines = 0, set the
    >> width, and have the height of the label expand vertically to contain all of
    >> the text, and then use it's height to help determine the height the cell
    >> itself needs to be? The result would be a UITableView with rows of varying
    >> heights, perfectly framing each row's content.
    >>
    >> I was using a UIWebView to display the summary since it came with tons of
    >> html tags in it, but I've since just stripped all of the tags out of each
    >> item's summary.
    >>
    >> Thanks,
    >> Eric

  • I found a tutorial online just after I emailed this list. Thanks for the
    links!

    Eric

    On Thu, Jan 14, 2010 at 9:57 AM, Luke the Hiesterman <luketheh...>wrote:

    > Hmm, those were supposed to be links at the end of the lines.
    >
    >
    > http://developer.apple.com/iphone/library/documentation/UIKit/Reference/NSS
    tring_UIKit_Additions/Reference/Reference.html#//apple_ref/doc/uid/TP400068
    93-CH3-SW7

    >
    >
    > http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIT
    ableViewDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UI
    TableViewDelegate/tableView:heightForRowAtIndexPath

    > :
    >
    > Luke
    >
    > On Jan 14, 2010, at 6:56 AM, Luke the Hiesterman wrote:
    >
    >> Calculate label height with [NSString
    > sizeWithFont:ForWidth:LineBreakMode:]. sizeWithFont:forWidth:lineBreakMode:
    >>
    >> Assign cell row heights with [UITableViewDelegate
    > tableView:heightForRowAtIndexPath:] – tableView:heightForRowAtIndexPath:
    >>
    >> Luke
    >>
    >> On Jan 14, 2010, at 6:46 AM, Eric E. Dolecki wrote:
    >>
    >>> I am pulling in an RSS feed, and each item has it's own summary of a
    > varying
    >>> amount of text. I am using a table and presently setting the height of
    > each
    >>> row the same to allow for the most text. This looks awful as some items
    > have
    >>> a lot of empty space for it's row.
    >>>
    >>> Is it possible to have a UILabel where I set numberOfLines = 0, set the
    >>> width, and have the height of the label expand vertically to contain all
    > of
    >>> the text, and then use it's height to help determine the height the cell
    >>> itself needs to be? The result would be a UITableView with rows of
    > varying
    >>> heights, perfectly framing each row's content.
    >>>
    >>> I was using a UIWebView to display the summary since it came with tons
    > of
    >>> html tags in it, but I've since just stripped all of the tags out of
    > each
    >>> item's summary.
    >>>
    >>> Thanks,
    >>> Eric

    >
    >

    --
    http://ericd.net
    Interactive design and development
  • Sure thing: http://www.cimgf.com/2009/09/23/uitableviewcell-dynamic-height/

    On Thu, Jan 14, 2010 at 1:06 PM, Jack Carbaugh <intrntmn...> wrote:

    > Could you share the tutorial with the group please .. that way if someone
    > else searches and finds this thread, they can continue to the tutorial.
    >
    > thanks!
    > jack
    >
    >
    > On Jan 14, 2010, at 10:05 AM, Eric E. Dolecki wrote:
    >
    > I found a tutorial online just after I emailed this list. Thanks for the
    >> links!
    >>
    >> Eric
    >>
    >> On Thu, Jan 14, 2010 at 9:57 AM, Luke the Hiesterman <luketheh...>
    >>> wrote:
    >>
    >> Hmm, those were supposed to be links at the end of the lines.
    >>>
    >>>
    >>>
    >>> http://developer.apple.com/iphone/library/documentation/UIKit/Reference/NSS
    tring_UIKit_Additions/Reference/Reference.html#/

    >>> /apple_ref/doc/uid/TP40006893-CH3-SW7
    >>>
    >>>
    >>>
    >>> http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIT
    ableViewDelegate_Protocol/Reference/Reference.html#/

    >>> /apple_ref/occ/intfm/UITableViewDelegate/tableView:heightForRowAtIndexPath
    >>> :
    >>>
    >>> Luke
    >>>
    >>> On Jan 14, 2010, at 6:56 AM, Luke the Hiesterman wrote:
    >>>
    >>> Calculate label height with [NSString
    >>>>
    >>> sizeWithFont:ForWidth:LineBreakMode:].
    >>> sizeWithFont:forWidth:lineBreakMode:
    >>>
    >>>>
    >>>> Assign cell row heights with [UITableViewDelegate
    >>>>
    >>> tableView:heightForRowAtIndexPath:] – tableView:heightForRowAtIndexPath:
    >>>
    >>>>
    >>>> Luke
    >>>>
    >>>> On Jan 14, 2010, at 6:46 AM, Eric E. Dolecki wrote:
    >>>>
    >>>> I am pulling in an RSS feed, and each item has it's own summary of a
    >>>>>
    >>>> varying
    >>>
    >>>> amount of text. I am using a table and presently setting the height of
    >>>>>
    >>>> each
    >>>
    >>>> row the same to allow for the most text. This looks awful as some items
    >>>>>
    >>>> have
    >>>
    >>>> a lot of empty space for it's row.
    >>>>>
    >>>>> Is it possible to have a UILabel where I set numberOfLines = 0, set the
    >>>>> width, and have the height of the label expand vertically to contain
    >>>>> all
    >>>>>
    >>>> of
    >>>
    >>>> the text, and then use it's height to help determine the height the cell
    >>>>> itself needs to be? The result would be a UITableView with rows of
    >>>>>
    >>>> varying
    >>>
    >>>> heights, perfectly framing each row's content.
    >>>>>
    >>>>> I was using a UIWebView to display the summary since it came with tons
    >>>>>
    >>>> of
    >>>
    >>>> html tags in it, but I've since just stripped all of the tags out of
    >>>>>
    >>>> each
    >>>
    >>>> item's summary.
    >>>>>
    >>>>> Thanks,
    >>>>> Eric
    >>>>>

    >>>>
    >>>
    >>>
    >>>
    >>
    >> --
    >> http://ericd.net
    >> Interactive design and development
    >>
    >

    --
    http://ericd.net
    Interactive design and development
  • Be sure to still have a maximum height for each row. Some RSS feeds (eg. BetaNews.com) contain the entire article rather than just text.

    Also, some feeds contain images (eg. Online comics and the entire cheese burger network stuff).

    On 15/01/2010, at 05:16 , Eric E. Dolecki wrote:

    > Sure thing: http://www.cimgf.com/2009/09/23/uitableviewcell-dynamic-height/
    >
    > On Thu, Jan 14, 2010 at 1:06 PM, Jack Carbaugh <intrntmn...> wrote:
    >
    >> Could you share the tutorial with the group please .. that way if someone
    >> else searches and finds this thread, they can continue to the tutorial.
    >>
    >> thanks!
    >> jack
    >>
    >>
    >> On Jan 14, 2010, at 10:05 AM, Eric E. Dolecki wrote:
    >>
    >> I found a tutorial online just after I emailed this list. Thanks for the
    >>> links!
    >>>
    >>> Eric
    >>>
    >>> On Thu, Jan 14, 2010 at 9:57 AM, Luke the Hiesterman <luketheh...>
    >>>> wrote:
    >>>
    >>> Hmm, those were supposed to be links at the end of the lines.
    >>>>
    >>>>
    >>>>
    >>>> http://developer.apple.com/iphone/library/documentation/UIKit/Reference/NSS
    tring_UIKit_Additions/Reference/Reference.html#/

    >>>> /apple_ref/doc/uid/TP40006893-CH3-SW7
    >>>>
    >>>>
    >>>>
    >>>> http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIT
    ableViewDelegate_Protocol/Reference/Reference.html#/

    >>>> /apple_ref/occ/intfm/UITableViewDelegate/tableView:heightForRowAtIndexPath
    >>>> :
    >>>>
    >>>> Luke
    >>>>
    >>>> On Jan 14, 2010, at 6:56 AM, Luke the Hiesterman wrote:
    >>>>
    >>>> Calculate label height with [NSString
    >>>>>
    >>>> sizeWithFont:ForWidth:LineBreakMode:].
    >>>> sizeWithFont:forWidth:lineBreakMode:
    >>>>
    >>>>>
    >>>>> Assign cell row heights with [UITableViewDelegate
    >>>>>
    >>>> tableView:heightForRowAtIndexPath:] – tableView:heightForRowAtIndexPath:
    >>>>
    >>>>>
    >>>>> Luke
    >>>>>
    >>>>> On Jan 14, 2010, at 6:46 AM, Eric E. Dolecki wrote:
    >>>>>
    >>>>> I am pulling in an RSS feed, and each item has it's own summary of a
    >>>>>>
    >>>>> varying
    >>>>
    >>>>> amount of text. I am using a table and presently setting the height of
    >>>>>>
    >>>>> each
    >>>>
    >>>>> row the same to allow for the most text. This looks awful as some items
    >>>>>>
    >>>>> have
    >>>>
    >>>>> a lot of empty space for it's row.
    >>>>>>
    >>>>>> Is it possible to have a UILabel where I set numberOfLines = 0, set the
    >>>>>> width, and have the height of the label expand vertically to contain
    >>>>>> all
    >>>>>>
    >>>>> of
    >>>>
    >>>>> the text, and then use it's height to help determine the height the cell
    >>>>>> itself needs to be? The result would be a UITableView with rows of
    >>>>>>
    >>>>> varying
    >>>>
    >>>>> heights, perfectly framing each row's content.
    >>>>>>
    >>>>>> I was using a UIWebView to display the summary since it came with tons
    >>>>>>
    >>>>> of
    >>>>
    >>>>> html tags in it, but I've since just stripped all of the tags out of
    >>>>>>
    >>>>> each
    >>>>
    >>>>> item's summary.
    >>>>>>
    >>>>>> Thanks,
    >>>>>> Eric
    >>>>>>

    >>>>>
    >>>>
    >>>>
    >>>>
    >>>
    >>> --
    >>> http://ericd.net
    >>> Interactive design and development
    >>>
    >>
    >
    >
    > --
    > http://ericd.net
    > Interactive design and development
previous month january 2010 next month
MTWTFSS
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Go to today