gpt4 book ai didi

ios - 在Tableview Pull中使用QBSimpleSyncRefreshControl刷新时应用崩溃

转载 作者:行者123 更新时间:2023-12-03 17:33:12 25 4
gpt4 key购买 nike

我正在使用tabview Controller ,其中一个具有表 View 的 View Controller 是我使用QBSimpleSyncRefreshControl进行下拉刷新的,它在第一次加载Tab Controller 时可以正常工作,
当我注销用户时,我重新加载了Tab Controller (根 View Controller ),以至于应用程序意外崩溃。

这是我正在使用的代码

在tableview Controller 中

QBSimpleSyncRefreshControl *refreshControl = [[QBSimpleSyncRefreshControl alloc] init];
refreshControl.delegate = self;
self.myRefreshControl = refreshControl;
[self.tvTableView addSubview:self.myRefreshControl];

我在登出时
 UIStoryboard *board  = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UINavigationController *Tabctrl = [board instantiateViewControllerWithIdentifier:@"vcInitialViewNavId"];
UIWindow *window = AppDelegate.window;
[window addSubview:Tabctrl.view];
window.rootViewController = Tabctrl;

如果我挡住这条线
[self.tvTableView addSubview:self.myRefreshControl];

应用正常运行,如果注销后取消阻止该应用崩溃(重新加载根 View Controller )

任何人都可以为此提供帮助。

完整代码如下:

view.h文件
@interface MyTCView : UIViewController <UICollectionViewDataSource, UICollectionViewDelegate, QBRefreshControlDelegate>
{
// some declaration here
}

@property (weak, nonatomic) IBOutlet UITableView *tvTableView;

@property (nonatomic, strong) QBSimpleSyncRefreshControl *myRefreshControl;

View
- (void)viewDidLoad
{
[super viewDidLoad];

FeaturedItemTitle = @"";

HUD = [[MBProgressHUD alloc] initWithView:self.view];
HUD.mode = MBProgressHUDModeIndeterminate;
[self.view addSubview:HUD];

AppDelegate = (TCAppDelegate *) [UIApplication sharedApplication].delegate;
board = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];

QBSimpleSyncRefreshControl *refreshControl = [[QBSimpleSyncRefreshControl alloc] init];
refreshControl.delegate = self;
self.myRefreshControl = refreshControl;
[self.tvTableView addSubview:self.myRefreshControl];
}

- (void)refreshControlDidBeginRefreshing:(QBRefreshControl *)refreshControl
{
[self GetDetails];
}

-(void) GetDetails
{
// Calling web service here

NSString *strURL = @"URL HERE";

NSURL *url = [NSURL URLWithString: strURL];

NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];

[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];

[theRequest setHTTPMethod:methodType];

NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:delegate];

if ( theConnection ) {
//Connection successful
receivedData = [NSMutableData data];
} else {
//Failure
NSLog(@"Error");
}
}

//*** HTTP Connection ***//

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
receivedData = [[NSMutableData alloc] init];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[receivedData appendData:data];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
[HUD hide:YES];
[self ShowAlertMessage:ServerErrorMsg Tilte:@""];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSError *error;

NSDictionary *res = [NSJSONSerialization JSONObjectWithData:receivedData options:NSJSONReadingAllowFragments error:&error];

// Array of data get from Res(NSDictionary)

[tvTableView reloadData]; // Tableview Reload

[collView reloadData]; // Collectionview reload

[self.myRefreshControl endRefreshing];

[HUD hide:TRUE];
}

最佳答案

我认为这不是注销基于Navigationcontroller的应用程序的正确方法,只需使用以下标准方法来加载rootController

 [self.navigationController popToRootViewControllerAnimated:YES];

关于ios - 在Tableview Pull中使用QBSimpleSyncRefreshControl刷新时应用崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20682785/

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