TableView with little less performance - objective-c

I'll try to implement a TableView with 2 different kinds of cells, the first one is a higher Cell with a fullwidth image inside, all other cells got a little thumb image on the left side.
My problem it the performance of the TableView. If I scroll a list of maybe 20 items it jerks a bit. I've red something the performance and I'll hope the code is not so bad:
"Caching of images is not necessary to raise the performance" Is this right?
Does I reuse the cells in the right way.
Is that the normal way to use 2 different kinds of Cells?
Here is the important Part:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0 && indexPath.row == 0) {
return 160;
}
return 60;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellName = [[NSString alloc] init];
// [...]
if(indexPath.section == 0 && indexPath.row == 0){
cellName = #"FirstMainCell";
CellTemplateFirstNews *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
if(cell == nil){
cell = [[[NSBundle mainBundle] loadNibNamed:#"CellTemplateFirstNewsView" owner:nil options:nil] objectAtIndex:0];
}
NSURL *urlRowImage = [NSURL URLWithString:[[NSString alloc]initWithFormat:#"http://webserver.de/inhalte/news/title/%#", detailDataNews.title_picture]];
NSData *dataRowImage = [NSData dataWithContentsOfURL:urlRowImage];
UIImageView *firstNewsImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 160)];
firstNewsImageView.backgroundColor = [UIColor clearColor];
firstNewsImageView.opaque = NO;
firstNewsImageView.image = [UIImage imageWithData:dataRowImage];
cell.backgroundView = firstNewsImageView;
// [...]
return cell;
}else{
cellName = #"MainCell";
CellTemplateNews *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
if(cell == nil){
cell = [[[NSBundle mainBundle] loadNibNamed:#"CellTemplateNewsView" owner:nil options:nil] objectAtIndex:0];
}
NSURL *urlRowImage = [NSURL URLWithString:[[NSString alloc]initWithFormat:#"http://webserver.de/inhalte/news/cover/%#", detailDataNews.cover_picture]];
NSData *dataRowImage = [NSData dataWithContentsOfURL:urlRowImage];
UIImage *rowImage = [UIImage imageWithData:dataRowImage];
cell.thumbImage.image = rowImage;
// [...]
return cell;
}
}r

I think the main problem is the synchronous network request that's happening for every cell, whether it's reused or not. The culprit is dataWithContentsOfURL:.
Check out this apple sample code, or google the phrase "ios lazy table images". In this SO answer, I provide a fairly simple to implement method that takes care of the loading an image asynch, then finding and updating the correct table view row upon completion.

One posibility is that you've forgotten to enter the CellIdentifier in your Xib. In fact the reuseIdentifier method needs your cell to have the same identifier, but you never set it when you create your cell. Those cells in your Xib have to have their identifier entered.

Do not alloc-init any object in cellForRowAtIndexPath You are probably leaking massive memory. Remember, this method called every time a cell comes into view, even cells that have been previously shown.
Also, your assignments to string variables are redundant. It is sufficient to do it like this.
BOOL firstCell = (indexPath.row==0 && indexPath.section==0);
NSString *cellIdentifier = firstCell ? #"FirstMainCell" : #"MainCell";
UITableViewCell *genericCell = [tableView
dequeueReusableCellWithIdentifier:cellIdentifier];
if (firstCell) {
cell = (CellTemplateFirstNews*) genericCell;
// configure...
}
else {
cell = (CellTemplateNews*) genericCell;
// configure...
}
return cell;
The other possible reason for your lag is the synchronous call to the web service. You are doing this each time the cell becomes visible. You need to load the images lazily and update the UI when necessary.

Related

Font size in UITextView change unexpectedly

I have a table view with several table view cell. The table view cell consists of title (using UILabel), picture (using UIWebView) and summary (using UITextView).
When I use UIImage for the picture, everything runs well. But then, I decided to display the pic by using resized UIWebView instead of UIImage. Some of the summary in the UITextView change unexpectedly.
When I scrolled the table, the problem will sometimes disappear. But it can randomly appear again on different table view cell.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
TableViewCell *cell = (TableViewCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:#"TableViewCell" owner:self options:nil];
cell = table;
self.table = nil;
}
//Configure the cell...
Article *article = [_articleRepository fetchArticleById:[articleIds objectAtIndex:indexPath.row]];
cell.headline.text = article.articleTitle;
// Remove html tag
NSString *substringContent = [self stringByStrippingHTML:article.articleContent];
cell.content.text = substringContent;
cell.selectionStyle = UITableViewCellSelectionStyleGray;
ImageRepository *imageRepository = [[ImageRepository alloc]init];
Image *image = [imageRepository fetchImageById:article.articleImage];
NSMutableString *mutUrl = [[NSMutableString alloc]initWithString:image.imageUrl];
[mutUrl insertString:#"_thumb" atIndex:[mutUrl length]-4];
NSString *stringUrl = [[NSString alloc]initWithString:mutUrl];
NSString *htmlImage = [NSString stringWithFormat:#"<html><head><style type=\"text/css\">body{margin: 0; padding: 0;}</style></head><body><img src=\"%#\"></body></html>", stringUrl];
[cell.image loadHTMLString:htmlImage baseURL:nil];
return cell;
}
It could be due to reuse of cells in the tableview that make ur problem appear randomly across cells. Would help if you posted code of what you've done.
EDIT: Try changing ur portion of the code to the one given below.
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:#"TableViewCell" owner:self options:nil];
cell = [topLevelObjects objectAtIndex:0];
}
Some questions:
1. Why are you doing cell = table & self.table = nil ?

Reloading searchResultsTableView

I have, in my main tableView, some custom cells (cells with an imageView, basically).
The imageView is set only if a value on my plist is false. Then, when it's true, the imageView is nil.
Basically when the user enters the detailView, the value is set to YES and the cell.imageView is nil.
And it's okay, it works
I'm using a searchDisplayController, when i search for something that has a cell.imageView, going into the detailView and then coming back to the searchResultsTable, the cell has still the image, while it shouldn't, but the main tableView has the correct cell (so, with no image).
I thought that it could depend on searchResultsTableView, but i'm not sure.
I tried with
[self.searchDisplayController.searchResultsTableView reloadData];
with no effect.
How could i reload the searchResultsTableView so that it shows the right cells, those with the image and those that don't have the image anymore?
Any help appreciated!
EDIT
This is my cellForRowAtIndexPath method:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
NSArray *rows;
if (tableView == self.searchDisplayController.searchResultsTableView) {
rows = filteredList; //for search
} else {
NSDictionary *section = [localSortedTips objectAtIndex:indexPath.section];
rows = [section objectForKey:#"Rows"];
}
NSDictionary *item = [rows objectAtIndex:indexPath.row];
cell.textLabel.text = [item objectForKey:#"name"];
if ([[item valueForKey:#"isRead"] boolValue] == NO) {
cell.imageView.image = [UIImage imageNamed:#"unread.png"];
} else {
cell.imageView.image = nil;
}
cell.textLabel.font = [UIFont boldSystemFontOfSize:15.0];
cell.textLabel.adjustsFontSizeToFitWidth = YES;
return cell;
}
If I understood you right, then you can have a workaround but searching again with the same search string:
if (self.searchDisplayController.active) {
self.searchDisplayController.searchBar.text = self.searchDisplayController.searchBar.text;
}
put it in viewWillAppear: or viewDidAppear: which will be called each time the view is shown up (eg. you go back from the detail view to your search view). And reloading the data in this place would be nice too, to get the right data (for example if you marked the cell as read like in your sample code)
Just [self.tableView reloadData]; and not the searchResultsTableView (it will be automatically use the updated data after the new search)
It sounds as if perhaps your cells are being recycled and not reset properly. UITableView uses view recycling, so it's important that if you do something such as set an image you make sure it is explicitly set even when their isn't an image to display.
If you share your cellsForRowAtIndexPath code you might be able to get some more help.

Cocoa-Touch – UITableView dequeueReusableCellWithIdentifier gives me wrong cell data

I'm trying to use a UITextField inside a UITableViewCell as you can see in the code below. It seems that when the tableview goes off screen some data that are supposed to be in the cells are mixed up. I would think that there is some problem going on with the method [tableView dequeueReusableCellWithIdentifier:addGroupContactCellIdentifier]; not being able to give me a "proper" cell after the tableview has gone off screen. What is the reason for this?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *addGroupContactCellIdentifier = #"AddGroupContactCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:addGroupContactCellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:addGroupContactCellIdentifier];
if ([indexPath section] == 0) { // Group Name Section
cell.textLabel.text = #"Name";
UITextField *groupNameTextField = [[UITextField alloc]initWithFrame:CGRectMake(80, 10, 210, 22)];
groupNameTextField.textAlignment = UITextAlignmentLeft;
groupNameTextField.backgroundColor = [UIColor clearColor];
groupNameTextField.placeholder = #"Type Group Name";
//groupNameTextField.borderStyle = UITextBorderStyleLine;
groupNameTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
groupNameTextField.returnKeyType = UIReturnKeyDone;
groupNameTextField.autocapitalizationType = UITextAutocapitalizationTypeSentences;
groupNameTextField.delegate = self;
[cell.contentView addSubview:groupNameTextField];
}
}
if ([indexPath section] == 1) { // Contacts Section
cell.textLabel.text = [[self.selectedPeoplePickerContacts objectAtIndex:[indexPath row]] objectForKey:#"name"];
cell.detailTextLabel.text = [[self.selectedPeoplePickerContacts objectAtIndex:[indexPath row]] objectForKey:#"number"];
}
cell.accessoryType = UITableViewCellAccessoryNone;
return cell;
}
UPDATE:
So I subclassed UITableViewCell but still it exhibits the same error as before. This is now my code for tableView:cellForRowAtIndexPath::
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *addGroupContactCellIdentifier = #"AddGroupContactCell";
if ([indexPath section] == 0) {
UITableViewCellWithUITextField *cell = [tableView dequeueReusableCellWithIdentifier:addGroupContactCellIdentifier];
if (cell == nil) {
//cell = [[UITableViewCellWithUITextField alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:addGroupContactCellIdentifier];
cell = [[UITableViewCellWithUITextField alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:addGroupContactCellIdentifier textFieldPlaceholder:#"Type Group Name" textFieldDelegate:self];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.text = #"Name";
// Need to set the UITableViewCell's textLabel properties otherwise they will cover the UITextField
cell.textLabel.opaque = NO;
cell.textLabel.backgroundColor = [UIColor clearColor];
return cell;
} else {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:addGroupContactCellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:addGroupContactCellIdentifier];
}
cell.textLabel.text = [[self.selectedPeoplePickerContacts objectAtIndex:[indexPath row]] objectForKey:#"name"];
cell.detailTextLabel.text = [[self.selectedPeoplePickerContacts objectAtIndex:[indexPath row]] objectForKey:#"number"];
return cell;
}
}
Third EDIT (I have now 2 different reuseIdentifiers which seem to give me my wanted results):
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if ([indexPath section] == 0) { // Group Name Section
static NSString *groupNameCellIdentifier = #"GroupNameCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:groupNameCellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:groupNameCellIdentifier];
cell.textLabel.text = #"Name";
UITextField *groupNameTextField = [[UITextField alloc]initWithFrame:CGRectMake(80, 10, 210, 22)];
groupNameTextField.textAlignment = UITextAlignmentLeft;
groupNameTextField.backgroundColor = [UIColor clearColor];
groupNameTextField.placeholder = #"Type Group Name";
//groupNameTextField.borderStyle = UITextBorderStyleLine;
groupNameTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
groupNameTextField.returnKeyType = UIReturnKeyDone;
groupNameTextField.autocapitalizationType = UITextAutocapitalizationTypeSentences;
groupNameTextField.delegate = self;
[cell.contentView addSubview:groupNameTextField];
}
// Customization
return cell;
} else {
static NSString *addGroupContactCellIdentifier = #"AddGroupContactCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:addGroupContactCellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:addGroupContactCellIdentifier];
}
// Customization
cell.textLabel.text = [[self.selectedPeoplePickerContacts objectAtIndex:[indexPath row]] objectForKey:#"name"];
cell.detailTextLabel.text = [[self.selectedPeoplePickerContacts objectAtIndex:[indexPath row]] objectForKey:#"number"];
return cell;
}
}
Subclassing is not necessary as some have suggested.
But you cannot use logic like "if ([indexPath section] == 0) {" inside of the "if (cell == nil) {" because that is only called the first time the cell is created, and it will be-re used at other indexes on subsequent recycles.
Instead, you need to use two different CellIdentifiers, so that cells you have set up for section zero do not get re-used at other places in the table. Put your if ([indexPath section] == 0) { before you dequeue the cell and use a different cell identifiers for section zero and subsequent section cells.
Also, make sure you do any indexpath-specific outside of the "if (cell == nil) {" so that it will be applied each time the cell is re-used not just the first time it is created.
You are right ! The problem is definitely due to the reusability feature of UITableView. Apple has done it in such a was so that you can reuse cells, and it works beautifully at a performance stand-point ! And so, when you try scrolling up and down, and indexPath values continue to be the same and your tableView gets data from the cellForRowAtIndexPath that you had defined in your class !
Solution:
You will need to subclass your UITableViewCell and add a UITextField in your -(void)layoutSubviews method.
Then you will need to reference this CustomUITableViewCell and use that to load your TableView.
A link that will help : Read this !
The values are mixed up because when you go offscreen and then reload the table again the cells are dequed from the internal table cells pool but they are not reloaded in the same order they were in the table previously. Note that this mixing will happen even if you have a table with many rows and you scroll it. The solution is to store your textfield data in a "data source" array and then configure the cell.
EXPLANATION
Basically in your code there is one main conceptual flaw: once you have regenerated the cell, you don't configure the content properly (you don't configure it at all). What I mean is that initially, when the table is displayed the first time, the pool is empty. So each new cell that needs to be displayed is recreated from scratch (not dequed from the pool); let's say your table can show 10 cells on screen, so the first 10 cells will be all created from scratch with empty text fields.
Then you start entering text in these fields, and all works correctly.
At a certain point you start scrolling the cell: what happens is that all cells that are in the top will disappear from screen and stored (queued) in the table pool, with their textfield and its edited content; let's say you queue cell at row 0. When a new cell needs to be displayed on bottom of the screen the first thing your code does is to try to deque a cell. Now this time you have a cell in the pool (the cell that was at row 0), this cell is retrieved from the pool and placed in the table, INCLUDED THE TEXTFIELD CONTENT, at row 11. So "magically" you will find a text edited at row 0 in another row, 11. Besides the cells are retrieved in a sparse order from the pool, so after many textfield editings and scrollings you will have a complete mixup.
Solution, and this is the reason of the bug in your code: as soon as the cell has been created or dequed, configure it, that is set the textfield content. How to retrieve the textfield content? store in an array. This is why your view controller is a "data source", because you source data to fill the table. Storing data in the table is a mistake, due to this dequeing mechanism. Example:
groupNameTextField.text=[myTextFieldContentArray objectAtIndex:indexPath.row];
Another solution, but I don't suggest it, is to assign a unique identifier to each cell, that is:
NSString *myCellId = [NSString stringWithFormat:#"CellID_%d_%d",indexPath.section,indexPath.row];
In this case all cells will be enqued with a different name and you will never mix up them.
This solution is working most of the time but it is discouraged for two reasons:
a. it is non-optimal, as you don't reuse cells and so this takes extra memory for similar cells
b. you're not guaranteed that each cell is effectively queued, all in all this logic is inside the table and it's not exposed to the developer, so it may happen that you need to re-generate each time the cell when needed (performance loss).

Information in last two cells of UITableView is duplicate of first two

I have a UITableView which loads data from XML using the below code. It loads the information correctly, but the final two cells from the array are a repeat of the first two cells. I don't know if I'm loading it incorrectly; I NSLog out the values as I build the array and they are correct. I've also logged the final array and that's fine.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
ViewRoutesCell * aCell = (ViewRoutesCell *)[tableView dequeueReusableCellWithIdentifier:#"ViewRoutesCell"];
if (aCell == nil)
{
NSArray *arr = [[NSBundle mainBundle] loadNibNamed:#"ViewRoutesCell" owner:self options:nil];
for (NSObject *anObj in arr) {
AssessObject *newObj1 = [[AssessObject alloc] init];
newObj1=[totalArray objectAtIndex:indexPath.row];
UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:newObj1.routeImage]]];
aCell = (ViewRoutesCell *)anObj;
aCell.imgRoute.image = image;
aCell.lblRouteText.text = newObj1.routeText;
aCell.lblRouteImage.text = newObj1.routeImage;
}
}
return aCell;
}
It's loading to a custom cell. It seems to me that the problem may be related to the reuse of the cells. Any ideas?
You must re-write your code as following:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
ViewRoutesCell * aCell = (ViewRoutesCell *)[tableView dequeueReusableCellWithIdentifier:#"ViewRoutesCell"];
if (aCell == nil)
{
NSArray *arr = [[NSBundle mainBundle] loadNibNamed:#"ViewRoutesCell" owner:self options:nil];
aCell = (ViewRoutesCell *)[arr objectAtIndex:0];
}
AssessObject *newObj1 = [[AssessObject alloc] init];
newObj1=[totalArray objectAtIndex:indexPath.row];
UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:newObj1.routeImage]]];
aCell.imgRoute.image = image;
aCell.lblRouteText.text = newObj1.routeText;
aCell.lblRouteImage.text = newObj1.routeImage;
return aCell;
}
otherwise, you cells will be cached with old values.
You have to assign the value to the cell if aCell != nil
if aCell != nil, it means that it find a reusable cells from previous created.
Therefore aCell keep what you created before and show you the repeat value
The previous answers are not very clear.
So lets step through it.
Reuse
When a table cell goes off the screen (e.g. is no longer visible) it goes into a pool of cells that are available for reuse these cells are tagged with a reuseIdentifier which may be like in your example #"Cell".
Why do we need a pool?
alloc/init'ing objects is expensive and when scrolling a UITableView you could potentially be doing this a lot especially if the user scrolls fast. This will cause your UITableView's scrolling to become slow and jerky.
So how do I reuse?
The method tableView: cellForRowAtIndexPath: main purpose in life is to give your UITableView a cell to display.
So the first thing you do in this method is call the method dequeueReusableCellWithIdentifier:. The dequeueReusableCellWithIdentifier: method will check the pool of cells available for reuse and return nil if there are none or return a UITableViewCell for you to configure.
The following check:
if (aCell == nil) {
is used to determine if we have a cell we can just configure or if we need to create a new one.
If aCell is nil then there was not a UITableViewCell available for reuse therefore we need to create one and give it it's initial config. This is a great time to set things like colours and other properties that only need to be set once.
After this if block we know we have a UITableViewCell that we just need to configure so now you can go ahead and set any labels or properties that are different for every cell.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
ViewRoutesCell * aCell = (ViewRoutesCell *)[tableView dequeueReusableCellWithIdentifier:#"ViewRoutesCell"];
if (aCell == nil) {
// Create a new cell and do any one time config
}
// Configuration that is different for every cell
return cell;
}
Just make sure that you always explicitly set all aspects of the cell's content in your -tableView:cellForRowAtIdexPath: implementation. If you fail to do that, any views in the cell that you fail to set will continue to have whatever content they acquired in their previous use.

Double selection of a uitableviewcell in Custom Cell

i have an issue regarding UitableViewCell. the issue is that i have made a custom cell and i have a check box image button in that cell. i check and uncheck it. it works fine but the issue is that when i select Row # 1. it also selects row # 10 same goes with other rows like for 2 it will auto select row # 11. i am showing 10 rows at a time.
here is my code for CellForIndexPath
static NSString *cellIdentifier = #"Cell";
InterestsTableViewCell *cell = (InterestsTableViewCell *) [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell==nil) {
NSArray *arrayNibs = [[NSBundle mainBundle] loadNibNamed:#"InterestsTableViewCell" owner:self options:nil];
cell = [arrayNibs objectAtIndex:0];
cell.delegate = self;
cell.total = [dataArray count];
}
cell.tag = indexPath.row;
cell.lblTitle.text = [dataArray objectAtIndex:indexPath.row];
if (indexPath.row==0) {
cell.imgBg.image = [UIImage imageNamed:#"tableCell_top_default.png"];
}else if(indexPath.row == [dataArray count]-1){
cell.imgBg.image = [UIImage imageNamed:#"tableCell_bottom_default.png"];
}else{
cell.imgBg.image = [UIImage imageNamed:#"tableCell_middle_default.png"];
}
return cell;
Plus i am detecting touch so that i can change the background image (i have an other image as background). Code for Touch Began (in custom cell is below)
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
//NSLog(#"%i",tag);
isSelected = !isSelected;
btnTickMark.selected = !btnTickMark.selected;
(isSelected ? (onImage = YES) : (onImage = NO));
Can somebody help me in this issue that why 2 rows are selected when i click a row.
Thanks in advance
This is because UITableView dequeues the cell. As you are showing 10 rows per screen it totally fits, that row 11 appears checked as it is dequeued from row 1.
To avoid that behavior you have to add a check to tableView:cellForRowAtIndexPath: to set your checked parameter for each cell – like the text you set for every cell.
Try this:
NSArray *arrayNibs = [[NSBundle mainBundle] loadNibNamed:#"InterestsTableViewCell" owner:self options:nil];
for (id currentObject in arrayNibs){
if ([currentObject isKindOfClass:[UITableViewCell class]]){
cell = (InterestsTableViewCell *) currentObject;
cell.Delegate = self;
cell.total = [dataArray count];
break;
}
}
and let me know if this works for you.
Quick Fix - change this line from
InterestsTableViewCell *cell = (InterestsTableViewCell *) [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
to
InterestsTableViewCell *cell = nil;
Its not good from a memory/efficiency perspective because you won't be reusing the cells, instead will be reloading one from nib each time - but it will demonstrate whether what Florian Mielke is saying is correct (and his recommended approach will provide a better solution long term).