Note that there are some explanatory texts on larger screens.

plurals
  1. POCocos2d UITableView Edit Button Showing but not Showing Delete Icon
    primarykey
    data
    text
    <p>Ok, so my project (which does have Cocos2d) has 3 UITableViews. So far, I am only concerned with the first one, which is why I am only pasting the code for the first one. The problem is, whenever I use the app, the table view shows up, with all of it's content. The edit/done button also shows up as it is supposed to in the right hand corner. However, whenever I try to hit the edit button, the button switches to Done, but there is no delete icon near the cells, nor can I delete the cells. I have tried many solutions, but none of them seem to work. Thanks in advance.</p> <pre><code>-(id)init{ if (self == [super init]) { // Create initialized instance of UITabBarController tabController = [[UITabBarController alloc] init]; // Create initialized instance of NSMutableArray to hold our UINavigationControllers tabArray = [[NSMutableArray alloc] init]; // Create first UIViewController questionController = [[UIViewController alloc] init]; [self makeQuestionTable]; [questionController setTitle:@"Question"]; // Initialize the UINavigationController navigationController = [[UINavigationController alloc] initWithRootViewController:questionController]; questionController.navigationItem.rightBarButtonItem = questionController.editButtonItem; questionTableView.allowsSelection = YES; questionTableView.allowsMultipleSelectionDuringEditing = YES; questionTableView.allowsSelectionDuringEditing = YES; // Add UINavigationController to you tabs [tabArray addObject:navigationController]; // Release UIViewController and UINavigationController [questionController release], [navigationController release]; // Create second UIViewController answerController = [[UIViewController alloc] init]; [self makeAnswerTable]; [answerController setTitle:@"Answer"]; // Initialize the UINavigationController navigationController = [[UINavigationController alloc] initWithRootViewController:answerController]; // Add UINavigationController to you tabs [tabArray addObject:navigationController]; // Release UIViewController and UINavigationController [answerController release], [navigationController release]; // Create third UIViewController colorController = [[UIViewController alloc] init]; [self makeColorTable]; [colorController setTitle:@"Color"]; // Initialize the UINavigationController navigationController = [[UINavigationController alloc] initWithRootViewController:colorController]; // Add UINavigationController to you tabs [tabArray addObject:navigationController]; // Release UIViewController and UINavigationController [colorController release], [navigationController release]; // Add the tabs to the UITabBarController [tabController setViewControllers:tabArray]; // Add the view of the UITabBarController to the window [[[CCDirector sharedDirector]view]addSubview:tabController.view]; } return self; } -(void)setEditing:(BOOL)editing animated:(BOOL)animated{ [questionTableView setEditing:editing animated:animated]; [questionController setEditing:editing animated:animated]; } -(void)makeQuestionTable{ questionTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 480) style:UITableViewStylePlain]; questionTableView.backgroundColor = [UIColor whiteColor]; questionTableView.delegate = self; questionTableView.dataSource = self; questionTableView.tag = 1; [questionTableView reloadData]; [questionController.view addSubview:questionTableView]; } -(void)makeAnswerTable{ answerTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 400) style:UITableViewStylePlain]; answerTableView.backgroundColor = [UIColor whiteColor]; answerTableView.delegate = self; answerTableView.dataSource = self; answerTableView.tag = 2; [answerTableView reloadData]; [answerController.view addSubview:answerTableView]; } -(void)makeColorTable{ colorTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 400) style:UITableViewStylePlain]; colorTableView.backgroundColor = [UIColor whiteColor]; colorTableView.delegate = self; colorTableView.dataSource = self; colorTableView.tag = 3; [colorTableView reloadData]; [colorController.view addSubview:colorTableView]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (currentTab == 1) { return [appDelegate.questionArray count]; } else if (currentTab == 2) { return [appDelegate.answerArray count]; } else if (currentTab == 3) { return [appDelegate.colorArray count]; } else{ return 0; } } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { if (tableView.tag == 1) { static NSString *simpleTableIdentifier = @"SimpleTableItem"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier]; } cell.textLabel.text = [appDelegate.questionArray objectAtIndex:indexPath.row]; return cell; NSLog(@"Question"); } if(tableView.tag == 2){ static NSString *simpleTableIdentifier = @"SimpleTableItem"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier]; } cell.textLabel.text = [appDelegate.answerArray objectAtIndex:indexPath.row]; return cell; NSLog(@"Answer"); } if(tableView.tag == 3){ static NSString *simpleTableIdentifier = @"SimpleTableItem"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier]; } cell.textLabel.text = [appDelegate.colorArray objectAtIndex:indexPath.row]; return cell; NSLog(@"Color"); } } - (UITableViewCellEditingStyle)tableView:(UITableView*)tableView editingStyleForRowAtIndexPath:(NSIndexPath*)indexPath { UITableViewCell *cell = [questionTableView cellForRowAtIndexPath:indexPath]; if ([cell isEditing]) { NSLog(@"YES"); } else{ NSLog(@"NO"); } return UITableViewCellEditingStyleDelete; } // This only needs to be implemented if you are going to be returning NO // for some items. By default, all items are editable. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { // Return YES if you want the specified item to be editable. return YES; } // Override to support editing the table view. - (void)tableView:(UITableView *)tableView commitEditingStyle: (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { //add code here for when you hit delete [questionTableView delete:indexPath]; } } </code></pre>
    singulars
    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.
    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