gpt4 book ai didi

ios - 如何从类方法调用tableView

转载 作者:行者123 更新时间:2023-11-28 22:29:40 25 4
gpt4 key购买 nike

我在从 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];
}];
}

最佳答案

为了获得滑动效果,您需要实现 TableView 委托(delegate)

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

方法,这将提供对用于删除的滑动交互的访问。我通常也为可以删除的 TableView 提供编辑交互,因为滑动交互往往对用户有点隐藏。

举个例子:

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

希望对您有所帮助。

关于ios - 如何从类方法调用tableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17801340/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com