Hallo an Alle,
ich möchte gerne eine Uitableview mit Sections erstellen.
Die Daten werden aus einer Property List gelesen.
Ich habe 3 Sections mit jeweils 2 Zeilen. Das ganze wird auch so dargestellt.
Nur leider beginnt jede Section mit dem gleichen Eintrag, d.h. es wird wohl immer wieder von Anfang gezählt.
(Jede Sections hat den gleichen Inhalt)
Bestimmt hat das Problem mit meiner Property List zu tun. Diese ist nicht in die Sections unterteilt.
Oder kann man vielleicht sagen, das in der zweiten Section (section == 1) erst ab dem dritten Eintrag ( Item 2 ) aus der Property List gezählt werden soll?
Bin erst Anfänger und habe mich bereits Tage mit diesen Thema beschäftigt. Kriege es aber einfach nicht hin.
Für Eure Hilfe wäre ich sehr dankbar!
Viele Grüße
Bettina
Hier meine Tableview
Alles anzeigen
Hier meine Property List
Alles anzeigen
Hat jemand eine Idee
ich möchte gerne eine Uitableview mit Sections erstellen.
Die Daten werden aus einer Property List gelesen.
Ich habe 3 Sections mit jeweils 2 Zeilen. Das ganze wird auch so dargestellt.
Nur leider beginnt jede Section mit dem gleichen Eintrag, d.h. es wird wohl immer wieder von Anfang gezählt.
(Jede Sections hat den gleichen Inhalt)
Bestimmt hat das Problem mit meiner Property List zu tun. Diese ist nicht in die Sections unterteilt.
Oder kann man vielleicht sagen, das in der zweiten Section (section == 1) erst ab dem dritten Eintrag ( Item 2 ) aus der Property List gezählt werden soll?
Bin erst Anfänger und habe mich bereits Tage mit diesen Thema beschäftigt. Kriege es aber einfach nicht hin.
Für Eure Hilfe wäre ich sehr dankbar!
Viele Grüße
Bettina
Hier meine Tableview
Quellcode
- @interface PictureTableViewController ()
- @property (nonatomic, strong) NSArray *pictureArray;
- @end
- @implementation PictureTableViewController
- @synthesize pictureArray = _pictureArray;
- - (id)initWithStyle:(UITableViewStyle)style
- {
- self = [super initWithStyle:style];
- if (self) {
- // Custom initialization
- }
- return self;
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- }
- #pragma mark - View lifecycle
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- self.pictureArray = [[NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle]
- pathForResource:@"Bilder" ofType:@"plist"]] objectForKey:@"pictures"];
- }
- - (void)viewDidUnload
- {
- [super viewDidUnload];
- - (void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- }
- - (void)viewDidAppear:(BOOL)animated
- {
- [super viewDidAppear:animated];
- }
- - (void)viewWillDisappear:(BOOL)animated
- {
- [super viewWillDisappear:animated];
- }
- - (void)viewDidDisappear:(BOOL)animated
- {
- [super viewDidDisappear:animated];
- }
- - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
- {
- }
- #pragma mark - Table view data source
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- // Return the number of sections.
- return 3;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- if (section == 0) { // Lautsprecher....
- return 2;
- } else if (section == 1) { // Soundkarten
- return 2;
- }else if (section == 2) { // speicher
- return 2;
- }
- return 0;
- // Return the number of rows in the section.
- return [self.pictureArray count];
- }
- -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
- {
- if (section == 0) { // Lautsprecher....
- return @"Lautsprecher";
- } else if (section == 1) { // Soundkarten
- return @"Soundkarten";
- }else if (section == 2) { // speicher
- return @"Speicher";
- }
- return @"";
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *CellIdentifier = @"pictureCell";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
- // Configure the cell...
- NSDictionary *dict = [self.pictureArray objectAtIndex:indexPath.row];
- cell.imageView.image = [UIImage imageNamed:[dict objectForKey:@"filename"]];
- cell.textLabel.text = [dict objectForKey:@"description"];
- cell.detailTextLabel.text = [dict objectForKey:@"subtitle"];
- return cell;
- }
Hier meine Property List
XML-Quellcode
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
- <plist version="1.0">
- <dict>
- <key>pictures</key>
- <array>
- <dict>
- <key>subtitle</key>
- <string>text1</string>
- <key>filename</key>
- <string>audio-card-2.png</string>
- <key>description</key>
- <string>Ein Lautsprecher1</string>
- </dict>
- <dict>
- <key>subtitle</key>
- <string>text2</string>
- <key>filename</key>
- <string>audio-card-3.png</string>
- <key>description</key>
- <string>Ein Lautsprecher 2</string>
- </dict>
- <dict>
- <key>subtitle</key>
- <string>text3</string>
- <key>filename</key>
- <string>audio-card-4.png</string>
- <key>description</key>
- <string>Eine einfache Soundkarte1</string>
- </dict>
- <dict>
- <key>subtitle</key>
- <string>text4</string>
- <key>filename</key>
- <string>audio-card-4.png</string>
- <key>description</key>
- <string>Eine einfache Soundkarte2</string>
- </dict>
- <dict>
- <key>subtitle</key>
- <string>text5</string>
- <key>filename</key>
- <string>audio-card-4.png</string>
- <key>description</key>
- <string>Ein toller Speicher 2</string>
- </dict>
- <dict>
- <key>subtitle</key>
- <string>text5</string>
- <key>filename</key>
- <string>audio-card-4.png</string>
- <key>description</key>
- <string>Ein toller Speicher 1</string>
- </dict>
- </array>
- </dict>
- </plist>
Hat jemand eine Idee