ListView custom cell sample

3 posts, 1 answers
  1. Yunuen Sanchez
    Yunuen Sanchez avatar
    31 posts
    Member since:
    Aug 2009

    Posted 18 Mar 2015 Link to this post

    Hello.

    I would like change the layout inside a cell and add more data. Is it possible on TKListView? can I have a sample?

    Thanks
  2. Answer
    Jack
    Admin
    Jack avatar
    2335 posts

    Posted 19 Mar 2015 Link to this post

    Hello Yunuen,

    Yes, you can customize cell layout and content in TKListView. Follow those steps:

    1. Create a custom cell class which inherits from TKListViewCell:

    @interface MyListCell: TKListViewCell
    @end
     
    @implementation MyListCell
     
    - (instancetype)initWithFrame:(CGRect)frame
    {
        self = [super initWithFrame:frame];
        if (self) {
            // add your custom content here.
        }
        return self;
    }
     
    @end

    2. Register your cell by using the registerClass:forCellWithReuseIdentifier: method:
    [listView registerClass:[MyListCell class] forCellWithReuseIdentifier:@"cell"];

    3. Adopt TKListViewDataSource protocol and implement its listView:cellForItemAtIndexPath: method:
    - (TKListViewCell*)listView:(TKListView *)listView cellForItemAtIndexPath:(NSIndexPath *)indexPath
    {
        MyListCell *cell = [listView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
        // add initialization logic here
        return cell;
    }

    I hope this helps. Do not hesitate to contact us if you have further questions.

    Regards,
    Jack
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. DevCraft banner
  4. Yunuen Sanchez
    Yunuen Sanchez avatar
    31 posts
    Member since:
    Aug 2009

    Posted 19 Mar 2015 in reply to Jack Link to this post

    Thanks a lot!
Back to Top