Я могу отображать правильные напоминания в правильных ячейках, извлекая данные из базы данных, но проблема в том, что третье напоминание перезаписывается со вторым и четвертым напоминанием перезаписывается третьим и третьим, а четвертое напоминание перезаписывается вторым напоминанием и так далее. Я использовал разные метки и добавил в качестве подпредставления ячейки табличного представления. Вот мой код, пожалуйста, помогите мне исправить это
NSString * CellId = [NSString stringWithFormat: @ "S% 1dR% 1d", indexPath.section, indexPath.row];
UITableViewCell *cell = (UITableViewCell *)[view dequeueReusableCellWithIdentifier:CellId];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellId] autorelease];
view.backgroundColor = [UIColor clearColor];
cell.backgroundColor = [[UIColor alloc]initWithPatternImage:[UIImage imageNamed:@"reminderbutton.png"]];
if (indexPath.section == 0)
{
//Retrieve the values of database
const char *dbpath = [self.databasePath UTF8String];
sqlite3_stmt *statement;
switch (indexPath.row)
{
case 0:
{
UILabel *label1 = [[[UILabel alloc]initWithFrame:CGRectMake(26, 3, 30, 40)]autorelease];
label1.backgroundColor = [UIColor clearColor];
label1.textColor = [UIColor whiteColor];
UILabel *label2 = [[[UILabel alloc]initWithFrame:CGRectMake(45, 3, 100, 40)]autorelease];
label2.backgroundColor = [UIColor clearColor];
label2.textColor = [UIColor whiteColor];
UILabel *label3 = [[[UILabel alloc]initWithFrame:CGRectMake(119, 3, 100, 40)]autorelease];
label3.backgroundColor = [UIColor clearColor];
label3.textColor = [UIColor whiteColor];
UILabel *label4 = [[[UILabel alloc]initWithFrame:CGRectMake(198, 3, 120, 40)]autorelease];
label4.backgroundColor = [UIColor clearColor];
label4.textColor = [UIColor whiteColor];
if (sqlite3_open(dbpath, &remindersDB) == SQLITE_OK)
{
NSString *querySQL = [NSString stringWithFormat:@"SELECT * FROM reminders"];
const char *query_stmt = [querySQL UTF8String];
if (sqlite3_prepare_v2(self.remindersDB ,query_stmt , -1, &statement, NULL) == SQLITE_OK)
{
if (sqlite3_step(statement) == SQLITE_ROW)
{
NSString *ID = [[[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 0)]autorelease];
NSString *nameField = [[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 1)]autorelease];
NSString *eventField = [[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 2)]autorelease];
NSString *dateField = [[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 3)]autorelease];
label1.text = ID;
label2.text = nameField;
label3.text = eventField;
label4.text = dateField;
}
sqlite3_finalize(statement);
}
sqlite3_close(self.remindersDB);
}
[cell addSubview:label1];
[cell addSubview:label2];
[cell addSubview:label3];
[cell addSubview:label4];
}
break;
case 1:
{
UILabel *label5 = [[[UILabel alloc]initWithFrame:CGRectMake(26, 3, 30, 40)]autorelease];
label5.backgroundColor = [UIColor clearColor];
label5.textColor = [UIColor whiteColor];
UILabel *label6 = [[[UILabel alloc]initWithFrame:CGRectMake(48, 3, 100, 40)]autorelease];
label6.backgroundColor = [UIColor clearColor];
label6.textColor = [UIColor whiteColor];
UILabel *label7 = [[[UILabel alloc]initWithFrame:CGRectMake(119, 3, 100, 40)]autorelease];
label7.backgroundColor = [UIColor clearColor];
label7.textColor = [UIColor whiteColor];
UILabel *label8 = [[[UILabel alloc]initWithFrame:CGRectMake(198, 3, 120, 40)]autorelease];
label8.backgroundColor = [UIColor clearColor];
label8.textColor = [UIColor whiteColor];
if (sqlite3_open(dbpath, &remindersDB) == SQLITE_OK)
{
NSString *querySQL = [NSString stringWithFormat:@"SELECT * from reminders order by id limit 1 offset 1"];
const char *query_stmt = [querySQL UTF8String];
if (sqlite3_prepare_v2(self.remindersDB ,query_stmt , -1, &statement, NULL) == SQLITE_OK)
{
if (sqlite3_step(statement) == SQLITE_ROW)
{
NSString *ID = [[[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 0)]autorelease];
NSString *nameField = [[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 1)]autorelease];
NSString *eventField = [[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 2)]autorelease];
NSString *dateField = [[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 3)]autorelease];
label5.text = ID;
label6.text = nameField;
label7.text = eventField;
label8.text = dateField;
}
sqlite3_finalize(statement);
}
sqlite3_close(self.remindersDB);
}
[cell addSubview:label5];
[cell addSubview:label6];
[cell addSubview:label7];
[cell addSubview:label8];
}
case 2:
{
UILabel *label9 = [[[UILabel alloc]initWithFrame:CGRectMake(26, 3, 30, 40)]autorelease];
label9.backgroundColor = [UIColor clearColor];
label9.textColor = [UIColor whiteColor];
UILabel *label10 = [[[UILabel alloc]initWithFrame:CGRectMake(48, 3, 100, 40)]autorelease];
label10.backgroundColor = [UIColor clearColor];
label10.textColor = [UIColor whiteColor];
UILabel *label11 = [[[UILabel alloc]initWithFrame:CGRectMake(119, 3, 100, 40)]autorelease];
label11.backgroundColor = [UIColor clearColor];
label11.textColor = [UIColor whiteColor];
UILabel *label12 = [[[UILabel alloc]initWithFrame:CGRectMake(198, 3, 120, 40)]autorelease];
label12.backgroundColor = [UIColor clearColor];
label12.textColor = [UIColor whiteColor];
if (sqlite3_open(dbpath, &remindersDB) == SQLITE_OK)
{
NSString *querySQL = [NSString stringWithFormat:@"SELECT * from reminders order by id limit 1 offset 2"];
const char *query_stmt = [querySQL UTF8String];
if (sqlite3_prepare_v2(self.remindersDB ,query_stmt , -1, &statement, NULL) == SQLITE_OK)
{
if (sqlite3_step(statement) == SQLITE_ROW)
{
NSString *ID = [[[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 0)]autorelease];
NSString *nameField = [[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 1)]autorelease];
NSString *eventField = [[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 2)]autorelease];
NSString *dateField = [[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 3)]autorelease];
label9.text = ID;
label10.text = nameField;
label11.text = eventField;
label12.text = dateField;
}
sqlite3_finalize(statement);
}
sqlite3_close(self.remindersDB);
}
[cell addSubview:label9];
[cell addSubview:label10];
[cell addSubview:label11];
[cell addSubview:label12];
}
case 3:
{
UILabel *label13 = [[[UILabel alloc]initWithFrame:CGRectMake(26, 3, 30, 40)]autorelease];
label13.backgroundColor = [UIColor clearColor];
label13.textColor = [UIColor whiteColor];
UILabel *label14 = [[[UILabel alloc]initWithFrame:CGRectMake(45, 3, 100, 40)]autorelease];
label14.backgroundColor = [UIColor clearColor];
label14.textColor = [UIColor whiteColor];
UILabel *label15 = [[[UILabel alloc]initWithFrame:CGRectMake(119, 3, 100, 40)]autorelease];
label15.backgroundColor = [UIColor clearColor];
label15.textColor = [UIColor whiteColor];
UILabel *label16 = [[[UILabel alloc]initWithFrame:CGRectMake(198, 3, 120, 40)]autorelease];
label16.backgroundColor = [UIColor clearColor];
label16.textColor = [UIColor whiteColor];
if (sqlite3_open(dbpath, &remindersDB) == SQLITE_OK)
{
NSString *querySQL = [NSString stringWithFormat:@"SELECT * from reminders order by id limit 1 offset 3"];
const char *query_stmt = [querySQL UTF8String];
if (sqlite3_prepare_v2(self.remindersDB ,query_stmt , -1, &statement, NULL) == SQLITE_OK)
{
if (sqlite3_step(statement) == SQLITE_ROW)
{
NSString *ID = [[[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 0)]autorelease];
NSString *nameField = [[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 1)]autorelease];
NSString *eventField = [[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 2)]autorelease];
NSString *dateField = [[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 3)]autorelease];
label13.text = ID;
label14.text = nameField;
label15.text = eventField;
label16.text = dateField;
}
sqlite3_finalize(statement);
}
sqlite3_close(self.remindersDB);
}
[cell addSubview:label13];
[cell addSubview:label14];
[cell addSubview:label15];
[cell addSubview:label16];
}
Я также размещаю снимок экрана, который поможет экспертам разобраться в проблеме