There’s a strange issue with some of things I am using. Custom tableViewCell or db. In My app I made subclassing of UITableViewCell. My subviews are not transparent, so there shouldn’t be scrolling issues or impact on productivity. They look fine and only the problem is that I can see only 10 first cells, that after I am getting the same names of the NAME label and others repeated, while are fetching the right ids from database. It looks like
CAT id=12 >> DOG id=18
And in the place of CAT should be DOG. Clicking on CAT cell, I am getting DOG title. So it says, the label of viewCell is lier.
I tried to run same db selects in SQLiteStudio and they are OK. I am getting the full set of records. Did someone face the same issue and where’s the evil?
The DBAccess method:
-(NSMutableArray*)getNominals:(int)subCountryID
{
NSMutableArray *nominals=[[[NSMutableArray alloc]init]autorelease];
const char* sqlNominals=sqlite3_mprintf("SELECT noms.nominalID, noms.nominal,noms.nominalName,noms.nominalImg,noms.priority\
FROM nominals AS noms\
INNER JOIN NominalsAndSubCountriesRelation as rel\
ON noms.nominalID=rel.NominalID\
WHERE rel.SubcountruID=%i\
ORDER BY noms.priority",subCountryID);
sqlite3_stmt *statement;
int sqlResult = sqlite3_prepare_v2(database, sqlNominals, -1, &statement, NULL);
if ( sqlResult== SQLITE_OK)
{
while (sqlite3_step(statement) == SQLITE_ROW)
{
Nominal *nom=[[Nominal alloc]init];
nom.nominalID=sqlite3_column_int(statement, 0);
char *nominal=(char *)sqlite3_column_text(statement, 1);
char *nominalName=(char*)sqlite3_column_text(statement, 2);
char *nominalImg=(char*)sqlite3_column_text(statement, 3);
nom.nominal=(nominal)?[NSString stringWithUTF8String:nominal]: @"";
nom.nominalName=(nominalName)?[NSString stringWithUTF8String:nominalName]: @"";
nom.nominalImg=(nominalImg)?[NSString stringWithUTF8String:nominalImg]: @"";
[nominals addObject:nom];
[nom release];
}
sqlite3_finalize(statement);
}
else
{
[self dbConnectionError];
}
return nominals;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.nominalsArr count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
NominalsCustomCell *cell =(NominalsCustomCell*)[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[NominalsCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
Nominal *nominalsObj=[self.nominalsArr objectAtIndex:[indexPath row]];
[cell setTheNominals:nominalsObj];
}
return cell;
}
Thank you in advance.
Move the following code
outside of the
if (cell == nil)block, since it should be set whenever a cell is set up, no matter if new or a reused one. In your case you’re setting up data for only the newly created cells – reused ones are simply brought up by UITableView and displayed with originally set up data.Read some more about how the UITableView cell reusing works.