Hallo,
ich habe mal wieder ein kleines Problem und würde mich über Hilfe freuen
Für mein TableView nutze ich eine Postum TableViewCell (erstellt im IB). Je nach Section fülle ich sie unterschiedlich. Das funktioniert auch soweit ganz gut. Die Cell hat verschiedene Labels und immer einen detailbutton. je nach Sektion dann entweder einen löschen Button oder Play/Pause und löschen.
Alles anzeigen
Es war allerdings ein Krampf für Section 2 andere Buttons und Action einzufügen. Das Problem liegt genau da: Klicke ich auf einen Button (nr 5 oder 6) wird die richtige Methode aufgerufen. Zum Beispiel:
Alles anzeigen
Es wird immer der indexPath.row = 0 ausgegeben (sprich: ich bekomme immer das gleiche event)… Ich habe nach dem gleichem Schema auch in einer anderen TableView gearbeitet und dort funktioniert es. Das Problem wird jedoch bei den Buttons sein die ich da fleißig hinzufüge und entferne, denn das tue ich im anderen TabView nicht.
Ich hoffe, jemand kann mir helfen.
Vielen Dank,
Juji
ich habe mal wieder ein kleines Problem und würde mich über Hilfe freuen
Für mein TableView nutze ich eine Postum TableViewCell (erstellt im IB). Je nach Section fülle ich sie unterschiedlich. Das funktioniert auch soweit ganz gut. Die Cell hat verschiedene Labels und immer einen detailbutton. je nach Sektion dann entweder einen löschen Button oder Play/Pause und löschen.
Quellcode
- // give each row a content
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *MyIdentifier = @"CellForRecord";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
- //...
- //set the event for each state
- BigEvent* event;
- //fill event
- //configure labels for available information
- if( (indexPath.section == 1 && [self.model countOfSchedulingList]>0) ||
- (indexPath.section == 2 && [self.model countOfRecordedList]>0) )
- {
- if (cell == nil)
- {
- UIViewController *temporaryController = [[UIViewController alloc] initWithNibName:@"RecordCell" bundle:nil];
- cell = (RecordCellVC *)temporaryController.view;
- [temporaryController release];
- cell.selectionStyle = UITableViewCellSelectionStyleGray;
- }
- //....
- //detailbutton
- UIButton *detailbutton = (UIButton*) [cell viewWithTag:4];
- [detailbutton addTarget:self action:@selector(showDetails:) forControlEvents:UIControlEventTouchDown];
- NSString* path = [[NSBundle mainBundle] pathForResource:@"button-more_red" ofType:@"png"];
- UIImage* img = [UIImage imageWithContentsOfFile:path];
- [detailbutton setBackgroundImage:img forState:UIControlStateNormal];
- [detailbutton setTitle:@"" forState:UIControlStateNormal];
- }
- if(indexPath.section == 1 && [self.model countOfSchedulingList]>0) //schedul
- {
- //recordbutton or cancelbutton
- UIButton* recordbutton = (UIButton*)[cell viewWithTag:5];
- [recordbutton addTarget:self action:@selector(cancelRecordEvent:) forControlEvents:UIControlEventTouchUpInside];
- [recordbutton setTitle:@"" forState:UIControlStateNormal];
- NSString* path = [[NSBundle mainBundle] pathForResource:@"button-delete_red" ofType:@"png"];
- UIImage* img = [UIImage imageWithContentsOfFile:path];
- [recordbutton setBackgroundImage:img forState:UIControlStateNormal];
- UIButton* button = (UIButton*)[cell viewWithTag:6];
- [button removeFromSuperview];
- }
- if(indexPath.section == 2 && [self.model countOfRecordedList]>0) //finished
- {
- //delete recordbutton
- UIButton* recordbutton = (UIButton*)[cell viewWithTag:5];
- [recordbutton removeFromSuperview];
- UIButton* deletbutton = (UIButton*) [cell viewWithTag:6];
- [deletbutton removeFromSuperview];
- //button tag:5
- if(event.isOnAir == FALSE)
- {
- UIButton* recbutton = [UIButton buttonWithType:UIButtonTypeCustom];
- [recbutton addTarget:self action:@selector(playEvent:) forControlEvents:UIControlEventTouchUpInside];
- [recbutton setTitle:@"" forState:UIControlStateNormal];
- NSString* path = [[NSBundle mainBundle] pathForResource:@"button-play_red" ofType:@"png"];
- UIImage* img = [UIImage imageWithContentsOfFile:path];
- [recbutton setBackgroundImage:img forState:UIControlStateNormal];
- recbutton.frame = CGRectMake(270, 39, 30, 30);
- [cell addSubview:recbutton];
- }
- else if (event.isOnAir == TRUE)
- {
- UIButton* recbutton = [UIButton buttonWithType:UIButtonTypeCustom];
- [recbutton addTarget:self action:@selector(pauseEvent:) forControlEvents:UIControlEventTouchUpInside];
- [recbutton setTitle:@"" forState:UIControlStateNormal];
- NSString* path = [[NSBundle mainBundle] pathForResource:@"button-pause_red" ofType:@"png"];
- UIImage* img = [UIImage imageWithContentsOfFile:path];
- [recbutton setBackgroundImage:img forState:UIControlStateNormal];
- recbutton.frame = CGRectMake(270, 39, 30, 30);
- [cell addSubview:recbutton];
- }
- //buton tag:6
- UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
- [button addTarget:self action:@selector(deletionEvent:) forControlEvents:UIControlEventTouchUpInside];
- [button setTitle:@"" forState:UIControlStateNormal];
- NSString* path = [[NSBundle mainBundle] pathForResource:@"button-delete_red" ofType:@"png"];
- UIImage* img = [UIImage imageWithContentsOfFile:path];
- [button setBackgroundImage:img forState:UIControlStateNormal];
- button.frame = CGRectMake(232, 39, 30, 30);
- [cell addSubview:button];
- }
- event = nil;
- return cell;
- }
Es war allerdings ein Krampf für Section 2 andere Buttons und Action einzufügen. Das Problem liegt genau da: Klicke ich auf einen Button (nr 5 oder 6) wird die richtige Methode aufgerufen. Zum Beispiel:
Quellcode
- -(IBAction)playEvent:(id)sender
- {
- NSLog(@"play event");
- UITableViewCell *owningCell = (UITableViewCell*)[[sender superview]superview];
- //From the cell get its index path.
- NSIndexPath *indexPath = [self.tableView indexPathForCell:owningCell];
- BigEvent* event;
- event = [self.model.recordedList objectAtIndex:indexPath.row];
- fernbedienungAppDelegate* appDelegate = (fernbedienungAppDelegate*)[[UIApplication sharedApplication] delegate];
- [appDelegate playForID:event.eventID];
- event = nil;
- }
Es wird immer der indexPath.row = 0 ausgegeben (sprich: ich bekomme immer das gleiche event)… Ich habe nach dem gleichem Schema auch in einer anderen TableView gearbeitet und dort funktioniert es. Das Problem wird jedoch bei den Buttons sein die ich da fleißig hinzufüge und entferne, denn das tue ich im anderen TabView nicht.
Ich hoffe, jemand kann mir helfen.
Vielen Dank,
Juji