This is a migrated thread and some comments may be shown as answers.

ListView custom cell sample

2 Answers 93 Views
ListView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Yunuen Sanchez
Top achievements
Rank 1
Yunuen Sanchez asked on 18 Mar 2015, 04:07 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Jack
Telerik team
answered on 19 Mar 2015, 03:11 PM
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.

 
0
Yunuen Sanchez
Top achievements
Rank 1
answered on 19 Mar 2015, 04:37 PM
Thanks a lot!
Tags
ListView
Asked by
Yunuen Sanchez
Top achievements
Rank 1
Answers by
Jack
Telerik team
Yunuen Sanchez
Top achievements
Rank 1
Share this question
or