2

私のプロジェクト (Cocos2d がある) には 3 つの UITableView があります。これまでのところ、最初のものだけに関心があるため、最初のもののコードのみを貼り付けています。問題は、アプリを使用するたびに、すべてのコンテンツを含むテーブル ビューが表示されることです。編集/完了ボタンも右側の隅に表示されます。ただし、編集ボタンを押しようとすると、ボタンは [完了] に切り替わりますが、セルの近くに削除アイコンがなく、セルを削除することもできません。多くの解決策を試しましたが、どれもうまくいかないようです。前もって感謝します。

-(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];
}
}
4

3 に答える 3

0

editボタンアクションでは、setEditingとして与える必要がありますYES

[tableView setEditing:YES animated:YES];
于 2013-01-10T09:29:03.820 に答える
0

tableView のプロパティ 'editing' を 'YES' に設定します。お気に入り:

questionTableView.editing = YES;

次の行を削除します。

questionTableView.allowsMultipleSelectionDuringEditing = YES;

またはallowsMultipleSelectionDuringEditing、選択時に「いいえ」に設定します。

于 2013-01-10T09:18:26.273 に答える
0

init メソッドの直前にいくつかの閉じ中括弧- (void)setEditingがありません。return self;

于 2013-01-11T03:29:25.593 に答える