![](/img/trans.png)
[英]UIRefreshControl in tableview dies when try pull to refresh
[英]App crashed when using QBSimpleSyncRefreshControl in tableview pull to refresh
我正在使用tabview控制器,该视图控制器具有表视图,我使用QBSimpleSyncRefreshControl进行下拉刷新,它在第一次加载Tab控制器时工作正常,当我注销用户时,我重新加载了Tab控制器(根视图控制器),时间应用程序意外崩溃。
这是我正在使用的代码
在tableview控制器中
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.h文件
@interface MyTCView : UIViewController <UICollectionViewDataSource, UICollectionViewDelegate, QBRefreshControlDelegate>
{
// some declaration here
}
@property (weak, nonatomic) IBOutlet UITableView *tvTableView;
@property (nonatomic, strong) QBSimpleSyncRefreshControl *myRefreshControl;
视图
- (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];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.