tableview wechselnde Inhalte

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • tableview wechselnde Inhalte

    Hallo,

    an was kann das liegen, wenn ich bei einem Tableview hoch- und runterscrolle sich der Inhalt immer neu und komplett anders anordnet?
    Zudem erscheinen einige Inhalte doppelt.

    Ich parse den Webservice und fülle es in ein Array. Den Array stopfe ich ein ein Dictionary mit Key und fülle abhängig von indexpath.row und Key im cellForRowAtIndex den Tableview.

    Anbei habe ich ein Link für ein Screencapturing Video: youtube.com/watch?v=yIi3MRLVEUs&feature=youtube_gdata_player

    Gruß
    lernen, lernen, lernen :)
  • ViewDidLoad: Webservice Parse:

    Quellcode

    1. - (void)viewDidLoad
    2. {
    3. [super viewDidLoad];
    4. //webservice
    5. NSString *urlString = [NSString stringWithFormat:@"http://www2.hs-augsburg.de/infoterm-fki-test/Webservice/ClientService.php?GetStructures"];
    6. NSURL *url = [NSURL URLWithString:urlString];
    7. NSData *data = [NSData dataWithContentsOfURL:url];
    8. NSError *error;
    9. structureArray = (NSArray*)[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
    10. NSLog(@"structure Array count: %i", structureArray.count);
    11. //test
    12. for (int i = 0; i<structureArray.count; i++) {
    13. NSLog(@"structure:%@", [[structureArray objectAtIndex:i] objectForKey:@"STRUCTURE_NAME"]);
    14. }
    15. }
    Alles anzeigen


    CellForRowAtIndexPath: füllen der Zellen

    Quellcode

    1. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    2. {
    3. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    4. if (cell == nil) {
    5. cell =[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    6. // Configure the cell...
    7. NSDictionary *cellValue = [structureArray objectAtIndex:indexPath.row];
    8. cell.textLabel.text = [cellValue objectForKey:@"STRUCTURE_NAME"];
    9. cell.textLabel.font = [UIFont systemFontOfSize:14.0];
    10. }
    11. return cell;
    12. }
    Alles anzeigen


    hm...
    lernen, lernen, lernen :)
  • imoney91 schrieb:

    Den Array stopfe ich ein ein Dictionary mit Key und fülle abhängig von indexpath.row und Key im cellForRowAtIndex den Tableview.

    Ich denke, da wird das Problem liegen, wenngleich ich nicht weiß, wie deine Abhängigkeit aussieht.
    «Applejack» "Don't you use your fancy mathematics to muddle the issue!"

    Iä-86! Iä-64! Awavauatsh fthagn!

    kmr schrieb:

    Ach, Du bist auch so ein leichtgläubiger Zeitgenosse, der alles glaubt, was irgendwelche Typen vor sich hin brabbeln. :-P
  • ich habe mal testweise in einer schleife mein Array ausgegeben, den ich vom webservice bekomme:

    2012-05-21 15:17:36.005 infoterm[4459:f803] structure Array count: 17
    2012-05-21 15:17:36.007 infoterm[4459:f803] structure:Informatik
    2012-05-21 15:17:36.008 infoterm[4459:f803] structure:Interaktive Medien (Bachelor)
    2012-05-21 15:17:36.009 infoterm[4459:f803] structure:Informatik (Bachelor)
    2012-05-21 15:17:36.009 infoterm[4459:f803] structure:Technische Informatik (Bachelor)
    2012-05-21 15:17:36.010 infoterm[4459:f803] structure:Wirtschaftsinformatik (Bachelor)
    2012-05-21 15:17:36.011 infoterm[4459:f803] structure:Interaktive Mediensysteme (Master)
    2012-05-21 15:17:36.011 infoterm[4459:f803] structure:Informatik (Master)
    2012-05-21 15:17:36.012 infoterm[4459:f803] structure:Wirtschaftsinformatik (Master)
    2012-05-21 15:17:36.012 infoterm[4459:f803] structure:Gestaltung
    2012-05-21 15:17:36.013 infoterm[4459:f803] structure:Maschinenbau
    2012-05-21 15:17:36.013 infoterm[4459:f803] structure:I-Bau
    2012-05-21 15:17:36.014 infoterm[4459:f803] structure:M-Bau
    2012-05-21 15:17:36.014 infoterm[4459:f803] structure:G-Bau
    2012-05-21 15:17:36.016 infoterm[4459:f803] structure:W-Bau
    2012-05-21 15:17:36.017 infoterm[4459:f803] structure:Vorschau
    2012-05-21 15:17:36.019 infoterm[4459:f803] structure:Hochschulweite Nachrichten
    2012-05-21 15:17:36.044 infoterm[4459:f803] structure:Gebäudeweite Nachrichten


    So sollte es auch im TableView ausschauen.
    lernen, lernen, lernen :)
  • Sieht sauber aus.
    Kannst du dafür garantieren, dass sich die Struktur des Arrays nicht verändert?
    Jedes Scrollen außerhalb der Bounds ruft ja automatisch ein reloadData auf. Wenn sich irgendwo dein Array verändert hat (z.B. Abfrage an den JSON im Hintergrund, weil er noch nicht fertig war.), wird auch deine Darstellung immer wieder verändert.
    «Applejack» "Don't you use your fancy mathematics to muddle the issue!"

    Iä-86! Iä-64! Awavauatsh fthagn!

    kmr schrieb:

    Ach, Du bist auch so ein leichtgläubiger Zeitgenosse, der alles glaubt, was irgendwelche Typen vor sich hin brabbeln. :-P
  • - Der 1. Fehler wäre schon mal die falsche Zuweisung von "dequeueReusableCellWithIdentifier:___"
    folgend von "initWithStyle:UITableViewCellStyleDefault reuseIdentifier:___" durch nen falschen static nsstring wert.

    - den autorelease kann ich aber weglassen wegen arc.

    - und letztenendes "objectAtIndex:" nach region und nicht nach row.

    Wenn ich es aber nach region mache, dann gibt er mir die Anzahl des Arrays mal den ersten Eintrag im Array aus.


    => stimmt cell config muss außerhalb der Klammer sein
    [Blockierte Grafik: http://i0.kym-cdn.com/photos/images/original/000/101/781/Y0UJC.png]
    haha DANKE xDDD

    jetzt bleibt nur noch die Tatsache, dass bei der Auswahl einer Zelle 2 Checkmarks gesetzt werden. Aber das muss ich mir jetzt anschauen.

    Vielen Dank nochmal an alle
    lernen, lernen, lernen :)

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von imoney91 ()

  • Jo hab ich schon probiert. Das Problem glaube ist, dass der Tableview nur eine Anzahl von Cells verwendet, das heißt wenn mein Array > 10 ist, und ich setze ein checkmark für Zelle 2, dann markiert er auch die Zelle 12. Ich habe es momentan so gelöst, dass ich ein NSIndexPath mit property anlege und die Anzahl der Zellen reinlade. Nach jedem Checkvorgang wird der Checkmark auch Wieder entfernt. Vllt find ich noch ne andere Lösung. Gruß
    lernen, lernen, lernen :)
  • Ich habe alle Zellen (Index.row ) in ein Array gespeichert, die ausgewählt wurden. Und entsprechend das Array gesäubert, wenn es deselected wurde.
    Mit diesem Array möchte ich jetzt in der Delegate Methode cellForRowAtIndexPath alle Zellen mit einem Checkmark versehen, die eben im Array notiert sind.

    Ich würde es mit einer for-schleife machen, die abhängig von der Größe meines Arrays ( Anzahl und Indexpathrow der gecheckten Zellen )
    durchlauft und in Abhängigkeit von dem inkrementierten i eben die Zelle mit einem cell.accessoryType = UITableViewCellAccessoryCheckmark versehen.

    Wie kann ich auf den Index jeder EINZELNEN Zelle im Tableview zugreifen um diese zu markieren oder eben nicht zu markieren?

    didSelectRowAtIndexPath

    Quellcode

    1. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    2. {
    3. UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    4. if (cell.accessoryType == UITableViewCellAccessoryNone) {
    5. cell.accessoryType = UITableViewCellAccessoryCheckmark;
    6. tempNumb = [NSNumber numberWithInt:indexPath.row];
    7. [arrayForCheckmark addObject:tempNumb];
    8. }
    9. else if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
    10. cell.accessoryType = UITableViewCellAccessoryNone;
    11. NSNumber *temp = [NSNumber numberWithInt:indexPath.row];
    12. if ([arrayForCheckmark containsObject:temp]) {
    13. [arrayForCheckmark removeObjectIdenticalTo:temp];
    14. }
    15. }
    16. [tableView deselectRowAtIndexPath:indexPath animated:YES];
    17. NSLog(@"Inhalt: %@", arrayForCheckmark);
    18. }
    Alles anzeigen


    celForRowAtIndexPath

    Quellcode

    1. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    2. {
    3. static NSString *MyIdentifier = @"structureCell";
    4. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
    5. if (cell == nil) {
    6. cell =[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier];
    7. }
    8. // Configure the cell...
    9. NSDictionary *cellValue = [offlineStructureArray objectAtIndex:indexPath.row];
    10. cell.textLabel.text = [cellValue objectForKey:@"STRUCTURE_NAME"];
    11. cell.textLabel.font = [UIFont systemFontOfSize:14.0];
    12. for (int i = 0; i>arrayForCheckmark.count; i++) {
    13. //pseudocode
    14. cell.accessorytype = [[cell atIndex [arrayForCheckmark objectAtIndex:i]] UITableViewCellAccessoryTypeCheckmark];
    15. }
    16. return cell;
    17. }
    Alles anzeigen
    lernen, lernen, lernen :)
  • Völlig falscher Ansatz.

    Wenn du mir helfen willst, dann sag was produktives und ned immer, dass es Quatsch ist etc. ...


    Wenns jemand interessiert. Meine Lösung:

    Quellcode

    1. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    2. {
    3. static NSString *MyIdentifier = @"structureCell";
    4. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
    5. if (cell == nil) {
    6. cell =[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier];
    7. }
    8. // Configure the cell...
    9. NSDictionary *cellValue = [offlineStructureArray objectAtIndex:indexPath.row];
    10. cell.textLabel.text = [cellValue objectForKey:@"STRUCTURE_NAME"];
    11. cell.textLabel.font = [UIFont systemFontOfSize:14.0];
    12. if ([[arrayForCheckmark objectAtIndex:indexPath.row] isEqual:@"1"]) {
    13. cell.accessoryType = UITableViewCellAccessoryCheckmark;
    14. }
    15. else{
    16. cell.accessoryType = UITableViewCellAccessoryNone;
    17. }
    18. return cell;
    19. }
    20. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    21. {
    22. UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    23. if (cell.accessoryType == UITableViewCellAccessoryNone) {
    24. cell.accessoryType = UITableViewCellAccessoryCheckmark;
    25. NSString *tempCountOne= @"1";
    26. [arrayForCheckmark replaceObjectAtIndex:indexPath.row withObject:tempCountOne];
    27. }
    28. else if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
    29. cell.accessoryType = UITableViewCellAccessoryNone;
    30. NSString *tempCountZero = @"0";
    31. [arrayForCheckmark replaceObjectAtIndex:indexPath.row withObject:tempCountZero];
    32. }
    33. [tableView deselectRowAtIndexPath:indexPath animated:YES];
    34. NSLog(@"Inhalt: %@", arrayForCheckmark);
    35. }
    Alles anzeigen
    lernen, lernen, lernen :)