我是一名有用的助手,可以为您翻译文本。
我有两个视图控制器页面。添加提醒页面包含保存按钮作为导航栏右侧按钮。
我之前遇到了关于查看提醒页面中表格视图部分数量的问题,这取决于添加提醒页面中保存的数量。
我找到了一个解决方案,可以根据保存的提醒数量生成单元格。
以下是代码:
我已经插入了四个提醒,四个单元格已经出现,但问题在于显示方面。
它的显示如下:
请帮我解决这个问题,提前感谢您的帮助 :)
对不起大家...我在以下链接中找到了解决方法: 检索在sqlite数据库中插入的所有行,并在包含标签子视图的表视图单元格中显示不同部分的标签 抱歉提出这个问题...感谢所有查看此问题的人,如果有用,请使用它
因此,我不会删除这个问题,再见TC :)
我有两个视图控制器页面。添加提醒页面包含保存按钮作为导航栏右侧按钮。
我之前遇到了关于查看提醒页面中表格视图部分数量的问题,这取决于添加提醒页面中保存的数量。
我找到了一个解决方案,可以根据保存的提醒数量生成单元格。
以下是代码:
-(NSInteger)numberOfSectionsInTableView:(UITableView *)view
{
NSInteger numTableRecords = -1;
sqlite3_stmt *statement;
if (sqlite3_open([self.databasePath UTF8String], &remindersDB) == SQLITE_OK)
{
NSString *sqlStatement = [NSString stringWithFormat: @"select count(*) from reminders"];
const char *sql = [sqlStatement cStringUsingEncoding:NSUTF8StringEncoding];
if(sqlite3_prepare_v2(remindersDB, sql, -1, &statement, NULL) == SQLITE_OK)
{
while(sqlite3_step(statement) == SQLITE_ROW)
{
numTableRecords = sqlite3_column_int(statement, 0);
}
}
else
{
printf("could not prepare statement: %s\n", sqlite3_errmsg(remindersDB));
}
}
else
{
NSLog(@"Error in Opening Database File");
}
sqlite3_close(remindersDB);
return numTableRecords;
}
现在我的问题是,我能够检索数据,但不是以适当的方式。我的意思是,这是我用来检索数据的代码:
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellId] autorelease];
view.backgroundColor = [UIColor clearColor];
cell.backgroundColor = [[UIColor alloc]initWithPatternImage:[UIImage imageNamed:@"reminderbutton.png"]];
label1 = [[[UILabel alloc]initWithFrame:CGRectMake(26, 3, 30, 40)]autorelease];
label1.backgroundColor = [UIColor clearColor];
label1.textColor = [UIColor whiteColor];
label2 = [[[UILabel alloc]initWithFrame:CGRectMake(45, 3, 100, 40)]autorelease];
label2.backgroundColor = [UIColor clearColor];
label2.textColor = [UIColor whiteColor];
label3 = [[[UILabel alloc]initWithFrame:CGRectMake(119, 3, 100, 40)]autorelease];
label3.backgroundColor = [UIColor clearColor];
label3.textColor = [UIColor whiteColor];
label4 = [[[UILabel alloc]initWithFrame:CGRectMake(198, 3, 120, 40)]autorelease];
label4.backgroundColor = [UIColor clearColor];
label4.textColor = [UIColor whiteColor];
//Retrieve the values of database
const char *dbpath = [self.databasePath UTF8String];
sqlite3_stmt *statement;
if (sqlite3_open(dbpath, &remindersDB) == SQLITE_OK)
{
NSString *querySQL = [NSString stringWithFormat:@"SELECT * from reminders ORDER BY id"];
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];
}
return cell;
我已经插入了四个提醒,四个单元格已经出现,但问题在于显示方面。
它的显示如下:
请帮我解决这个问题,提前感谢您的帮助 :)
对不起大家...我在以下链接中找到了解决方法: 检索在sqlite数据库中插入的所有行,并在包含标签子视图的表视图单元格中显示不同部分的标签 抱歉提出这个问题...感谢所有查看此问题的人,如果有用,请使用它
因此,我不会删除这个问题,再见TC :)