这是我实现的 cellforRowAtIndexPath 方法
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
static NSString *cellIdentifier=@"myCell";
CustomTableCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell==nil)
{
cell=[[CustomTableCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
DBObjectClass * info=[StudentInformationArr objectAtIndex:indexPath.row];
cell.studIdLbl.text=[NSString stringWithFormat:@"%d",info.StudIDs];
cell.studNameLbl.text=info.StudentName;
cell.studEmailLbl.text=info.StudentEmail;
cell.StudcontactLbl.text=[NSString stringWithFormat:@"%d",info.StudentContact];
return cell;
}
其中 DBObjectClass 是 NSOBject 类模型类
这是我在 TableView 中显示数据的方式
-(NSMutableArray*)StudentInformation;
{
NSMutableArray *DBArray=[[NSMutableArray alloc]init];
NSString *query=@"SELECT * FROM StudInfo ORDER BY studid";
NSLog(@"Query is:%s",[query UTF8String]);
sqlite3_stmt *statement;
if (sqlite3_prepare_v2(_database, [query UTF8String], -1, &statement, nil)==SQLITE_OK)
{
while (sqlite3_step(statement)==SQLITE_ROW)
{
int studID=sqlite3_column_int(statement, 0);
char *studName=(char*)sqlite3_column_text(statement, 1);
char *studEmail=(char*)sqlite3_column_text(statement, 2);
int studContact= sqlite3_column_int(statement, 3);
NSString *name=[[NSString alloc]initWithUTF8String:studName];
NSString *email=[[NSString alloc]initWithUTF8String:studEmail];
DBObjectClass *DbObj=[[DBObjectClass alloc]initWithSID:studID SName:name SEmail:email SContact:studContact];
[DBArray addObject:DbObj];
}
sqlite3_finalize(statement);
}
sqlite3_close(_database);
return DBArray;
}
我正在尝试在这里实现删除查询
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
如何获得这项工作?任何帮助将不胜感激