0

tableViewからセルを削除するのに多くの問題がありました。スワイプすると表示されるスライドセルに3つのボタンがあり、スワイプを呼び出すメソッドはJBSliderViewControllerにあります。homeViewController に埋め込まれたクラス メソッドにアクセスするために、JBSliderViewController 内にインスタンス メソッドを作成して、homeViewController 内にある-(void)callDeleteFound+(void)deleteFound を呼び出します。

私の問題は、tableViewにアクセスして呼び出すことができず、– deleteRowsAtIndexPaths:withRowAnimation: nullcurrentTableを返すことです

助言がありますか?

JBSliderController 内

- (void)callDeletefound {
    [homeViewController deleteFound];

}

homeViewController内

+ (void)deleteFound {
    NSUserDefaults *userSessionData = [NSUserDefaults standardUserDefaults];
    NSString *userID = [userSessionData stringForKey:@"userID"];
    NSString *authKey = [userSessionData stringForKey:@"authKey"];
    NSString *appVersion = [userSessionData stringForKey:@"appVersion"];
    NSString *versionedURL = [NSString stringWithFormat:@"/ios/%@/", appVersion];
    NSURL *url = [NSURL URLWithString:@"http://website.com"];
    NSString *postPath = [NSString stringWithFormat:@"%@deletefind.php", versionedURL];
    AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];

    NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
                            userID, @"userid",
                            [MyClass friendID], @"friendid",
                            authKey, @"tempAuth",
                            nil];
    [httpClient postPath:postPath parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
        [SVProgressHUD showSuccessWithStatus:@"Removed from notifications"];
        NSMutableArray *notificationArray = [[NSUserDefaults standardUserDefaults] objectForKey:@"notificationsArray"];
        NSMutableArray *arrayThatYouCanRemoveObjects = [NSMutableArray arrayWithArray:notificationArray];
        NSLog(@"%@", [MyClass cellNum]);
        NSInteger *num = [[MyClass cellNum] integerValue];
        [arrayThatYouCanRemoveObjects removeObjectAtIndex:num];
        [currentTable deleteRowsAtIndexPaths:openedCellIndexPath withRowAnimation:UITableViewRowAnimationLeft];
        [currentTable reloadData];

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"[HTTPClient Error]: %@", error.localizedDescription);
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Fail" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
        [alert show];
    }];
}
4

2 に答える 2

2

スワイプの効果を得るには、テーブル ビュー デリゲートを実装する必要があります。

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

メソッドを使用すると、削除のためのスワイプ インタラクションへのアクセスが提供されます。スワイプ操作はユーザーから少し隠される傾向があるため、通常、削除が可能なテーブルビューにも編集操作を提供します。

例として:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  [tableView beginUpdates];    
  if (editingStyle == UITableViewCellEditingStyleDelete) {
    // Do whatever data deletion you need to do...
    // Delete the row from the data source
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationTop];      
  }       
  [tableView endUpdates];
}

それが役立つことを願っています。

于 2013-07-23T04:22:30.573 に答える
0

つまり、要素を追加または削除できないため、オブジェクトにはremoveObjectAtIndex: メソッドがありません。

  • プロパティをチェックして、NSArrayではなく であるかどうかを確認してくださいNSMutableArray
  • そのポインタのオブジェクトが実際に であることを確認してくださいNSMutableArray
  • を変数に割り当てるには、まずメソッドを使用し NSArrayて変数から を作成します。NSMutableArrayarrayWithArray:
于 2013-07-23T04:20:33.217 に答える