Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom delete button in uitableview cell don't work
    primarykey
    data
    text
    <p>I made tableView with <strong>filteredReservations</strong> array wich contains Rezervacija objects. I added custom button "board", and when button is clicked, I ask with alert view to confirm this and then sending request to server. When receive server's response I need to delete row from table and object from filteredReservations array. When I delete first row it's ok, but after that in filteredReservations instead of Rezervacija object, I got UIButton objects! I don't know HOW :)</p> <p><strong>Code:</strong></p> <pre><code>- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return([filteredReservations count]); } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *MyIdentifier = @"MyIdentifier"; UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:MyIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] autorelease]; } Reservation *reservation = [filteredReservations objectAtIndex:indexPath.row]; NSString *label = [[NSString alloc] initWithFormat:@"%@ (%d)", reservation.name, reservation.seatsNumber]; cell.textLabel.text = label; [label release]; [reservation release]; tableView.allowsSelection = FALSE; UIButton *cellButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [cellButton setFrame:CGRectMake(430.0, 2.0, 106.0, 40.0)]; [cellButton setTitle:@"Board" forState:UIControlStateNormal]; [cellButton addTarget:self action:@selector(BoardPassengers:) forControlEvents:UIControlEventTouchUpInside]; [cell addSubview:cellButton]; cellButton.tag = indexPath.row; return cell; } -(void)BoardPassengers:(id)sender{ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Question" message:@"Do you want to board passengers?" delegate:self cancelButtonTitle:@"Odustani" otherButtonTitles:@"Da", nil]; [alert show]; [alert release]; passengerForBoarding = [NSIndexPath indexPathForRow:((UIControl*)sender).tag inSection:1]; } - (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { // the user clicked one of the OK/Cancel buttons if (buttonIndex == 0) { NSLog(@"cancel"); } else { Reservation *reservationNew = [filteredReservations objectAtIndex:passengerForBoarding.row]; NSString *reservationId = [[NSString alloc] initWithFormat:@"%d",reservationNew.reservationId]; params = [NSDictionary dictionaryWithObjectsAndKeys: @"1", @"tour_id", @"1", @"bus_number",reservationId, @"reservation_id", nil]; [[RKClient sharedClient] post:@"/service/boardingToBus.json" params:params delegate:self]; [DSBezelActivityView newActivityViewForView:self.view withLabel:@"Boarding..."]; } } - (void)request:(RKRequest*)request didLoadResponse:(RKResponse*)response { if([[request resourcePath] isEqualToString:@"/service/boardingToBus.json"]){ if([[response bodyAsString] isEqualToString:@"ERROR"]){ [DSBezelActivityView removeViewAnimated:YES]; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"Error." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; [alert release]; }else{ [DSBezelActivityView removeViewAnimated:YES]; [filteredReservations removeObjectAtIndex:passengerForBoarding.row]; [self.tableView reloadData]; //[self.tableView beginUpdates]; //[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:passengerForBoarding] // withRowAnimation:UITableViewRowAnimationFade]; // NSLog(@"%i", passengerForBoarding.row); //[self.tableView endUpdates]; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload