在tableview中使用QBSimpleSync Refresh Control进行刷新时,应用程序崩溃

时间:2013-12-19 13:16:03

标签: ios crash pull-to-refresh

我正在使用tabview控制器,其中一个具有表视图的视图控制器我使用QBSimpleSyncRefreshControl进行下拉刷新,它在第一次加载标签控制器中工作正常, 当我注销我的用户时,我重新加载我的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];

App工作正常,如果在注销时解除阻止此应用程序崩溃(重新加载根视图控制器)

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


完整代码在这里:

view.h文件

@interface MyTCView : UIViewController <UICollectionViewDataSource, UICollectionViewDelegate, QBRefreshControlDelegate>
{
   // some declaration here
}

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

@property (nonatomic, strong) QBSimpleSyncRefreshControl *myRefreshControl;

view.m

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

1 个答案:

答案 0 :(得分:0)

我认为这不是注销基于导航控制器的应用程序的正确方法,只需使用标准方式加载rootController

 [self.navigationController popToRootViewControllerAnimated:YES];