从 tableView 中删除单元格时,我遇到了很多麻烦。我在滑动单元格中有 3 个按钮,当滑动时显示,调用滑动的方法在 JBSliderViewController 中。为了访问嵌入在 homeViewController 中的类方法,我在 JBSliderViewController 中创建了一个实例方法-(void)callDeleteFound
来调用我的 homeViewController 中的 +(void)deleteFound。
我现在的问题是我无法访问我的 tableView 来调用– deleteRowsAtIndexPaths:withRowAnimation:
以及currentTable
返回 null
有什么建议么?
在 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];
}];
}