J'ai une base de données et je génère des données quelque chose comme ça.Comment générer des données différentes sur la ligne à partir de tableaux dans différentes sections de la cellule uitableview
D'abord obtenir categoryid et categoryName forment la base de données. Et le titre de la table est categoryName.
ici est un exemple de code
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return categoryNamesList.count;
}
-(NSString *) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [categoryNamesList objectAtIndex:section];
}
Je veux générer le nom flashcardid et linker sur la base de la catégorie id. categoryid est stocké dans la base de données comme 1,2,3.
donc je passe categoryid dans la requête:
select flashCardId,flashCardName from flashCardInfo where categoryId=(parameter)
Dans le flashcardid Je reçois 1,2,3 et dans le tableau des noms de FlashCards Je reçois flashcard1, flashcard2, flashcard3 première fois maintenant, je veux pour générer du texte sur ma cellule comme firstcategoryname sur la section 1, puis le nom de la carte flash associée sur les lignes puis sur le deuxième nom de la deuxième catégorie de la section et flashcardsNames connexes sur les lignes. Où augmenter l'ID de catégorie pour que j'obtenir les noms suivants nad id de et le comment de composer un texte sur les cellules
maintenant comment puis-je produis ceci sur
Voici le code; c'est dans le fichier indexviewcontroller.m
.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return categoryNamesList.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return flashCardsNamesList.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[CustomCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
if(categoryID<listOfCategoryId.count)
{
for(int i=0;i<flashCardsNamesList.count;i++)
{
[cell.FlashCardsNames setText:[flashCardsNamesList objectAtIndex:i]];
}
categoryID++;
[self getFlashCard:categoryID];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[indexTableView deselectRowAtIndexPath:indexPath animated:YES];
for(int i=0;i<flashCardsId.count;i++)
{
questionViewControllerObj = [[flashCardQuestionViewController alloc] initWithNibName:@"FlashCardQuestionView" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:questionViewControllerObj animated:YES];
questionViewControllerObj.flashcardid = [[flashCardsId objectAtIndex:i] intValue];
questionViewControllerObj.categoryid = [[listOfCategoryId objectAtIndex:indexPath.section]intValue];
}
}
/*
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
}
if (editingStyle == UITableViewCellEditingStyleInsert) {
}
}
*/
/*
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
*/
/*
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/
/*
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
*/
-(NSString *) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [categoryNamesList objectAtIndex:section];
}
# pragma mark -
# pragma mark viewDidLoad
- (void)viewDidLoad {
[super viewDidLoad];
[self getIntialData];
self.navigationItem.title = @"Index";
indexTableView.backgroundColor = [UIColor lightGrayColor];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated {
}
- (void)viewDidDisappear:(BOOL)animated {
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
#pragma mark -
#pragma mark Database Methods
-(void)getIntialData
{
[self getcategory];
[self getFlashCard:categoryID];
}
//getting categoryid,categoryname from the database
-(void)getcategory
{
if(listOfCategoryId!=nil)
[listOfCategoryId removeAllObjects];
else
listOfCategoryId = [[NSMutableArray alloc] init];
if(categoryNamesList!=nil)
[categoryNamesList removeAllObjects];
else
categoryNamesList = [[NSMutableArray alloc] init];
if(listOfCategoryType!=nil)
[listOfCategoryType removeAllObjects];
else
listOfCategoryType = [[NSMutableArray alloc] init];
clsDatabase *clsDatabaseObject = [[clsDatabase alloc] init];
sqlite3_stmt *dataRows = [clsDatabaseObject getDataset:"select categoryId,categoryName,categoryType from cardCategoryInfo"];
while(sqlite3_step(dataRows) == SQLITE_ROW)
{
[listOfCategoryId addObject:[NSNumber numberWithInt:sqlite3_column_int(dataRows,0)]];
[categoryNamesList addObject: [NSString stringWithUTF8String:(char *)sqlite3_column_text(dataRows,1)]] ;
[listOfCategoryType addObject:[NSNumber numberWithInt:sqlite3_column_int(dataRows,2)]];
}
sqlite3_finalize(dataRows);
[clsDatabaseObject release];
categoryID = [[listOfCategoryId objectAtIndex:categoryID] intValue];
}
//getting flashcardId and flashcard name from categoryid
-(void)getFlashCard:(int)categoryid
{
if(flashCardsId!=nil)
[flashCardsId removeAllObjects];
else
flashCardsId = [[NSMutableArray alloc] init];
if(flashCardsNamesList!=nil)
[flashCardsNamesList removeAllObjects];
else
flashCardsNamesList = [[NSMutableArray alloc] init];
NSString *martialStr=[NSString stringWithFormat:@"%d", categoryid];
NSString *queryStr=[[NSString alloc] initWithString:@"select flashCardId,flashCardName from flashCardInfo where categoryId="];
queryStr=[queryStr stringByAppendingString:martialStr];
unsigned int lengthOfString=[queryStr length];
char temp2[lengthOfString +1];
strcpy(temp2, [queryStr cStringUsingEncoding:NSUTF8StringEncoding]);
clsDatabase *clsDatabaseObject = [[clsDatabase alloc] init];
sqlite3_stmt *dataRows = [clsDatabaseObject getDataset:temp2];
while(sqlite3_step(dataRows) == SQLITE_ROW)
{
[flashCardsId addObject:[NSNumber numberWithInt:sqlite3_column_int(dataRows,0)]];
[flashCardsNamesList addObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(dataRows,1)]];
}
sqlite3_finalize(dataRows);
[clsDatabaseObject release];
}
- (void)dealloc {
[self.navigationController popViewControllerAnimated:YES];
[listOfCategoryId release];
[listOfCategoryType release];
[questionViewControllerObj release];
[categoryNamesList release];
[flashCardsNamesList release];
[flashCardsId release];
[indexTableView release];
[super dealloc];
}
@end
pourriez-vous s'il vous plaît poster le code avec mon exemple des tableaux –
Il serait utile si vous avez défini votre exemple des tableaux dans le code. J'ai mis à jour ma réponse pour demander plus d'informations. –
Je veux la même chose que vous avez écrit ci-dessus.Je suis en train d'éditer la question avec mon code pour vous donner une infeormation détaillée –