2013-01-03 63 views
0

我使用ASIHttpRequest下載我app.I文件顯示我爲每個文檔downloaded.The文件顯示在一個UITableView的progessbar的狀態,所以在每個文檔細胞單獨進度table.When用戶點擊「返回」,然後再次來到該文件表,我想顯示進度bar.But它不是下載文檔displayed.The代碼如下:堅持進度條

- (void)startDownloadingDocumentUsingIndexPath:(NSIndexPath*)indexPath 
{ 
    Document *document = [self.objects objectAtIndex:indexPath.row]; 
    self.ip=indexPath; 
    if(isNetworkAvailable) 
    { 
     NSString *str = [NSString stringWithFormat:kBody_convertDocToByte, 
         document.docCatId, 
         document.docCatName, 
         document.docChksum, 
         document.docLocation, 
         document.docName, 
         document.docSize, 
         document.docType, 
         document.docUpdated, 
         document.docUpdatedBy, 
         document.documentId 
         ]; 
     NSMutableData *data = [NSMutableData dataWithData:[str dataUsingEncoding:NSUTF8StringEncoding]]; 
     self.req = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:kURL]]; 

     self.req.shouldAttemptPersistentConnection = NO; 
     [self.req setDownloadProgressDelegate:_progress]; 

     self.req.delegate=APP_DEL; 
     self.req.timeOutSeconds=timeOut; 
     [self.req setDidFinishSelector:@selector(didFinishDownloadDocument:)]; 
     [self.req setDidFailSelector:@selector(didFailDownloadDocument:)]; 
     [self.req addRequestHeader:@"SOAPAction" value:kAction_convertDocToByte]; 
     [self.req addRequestHeader:@"Content-Type" value:@"text/xml; charset=utf-8"]; 
     [self.req setPostBody:data]; 
     [self.req setRequestMethod:@"POST"]; 
     [self.req setContentLength:[data length]]; 

     self.req.userInfo=[NSDictionary dictionaryWithObjectsAndKeys:document,@"data",self.objCategory.categoryName,@"catname",self,@"vctr", nil]; 
     [[APP_DEL nq] addOperation:self.req]; 
     [[APP_DEL nq] go]; 
     [APP_DEL nq].showAccurateProgress = YES; 
    } 
    else { 
     UIAlertView *av=[[UIAlertView alloc] initWithTitle:@"Message" message:@"Please connect to internet & try downloading/updating document later." delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil]; 
     [av show]; 
    } 
} 

我應該在代碼中做什麼修改,以保持進度條的狀態?

編輯: -文件表實際上,當用戶在「父」表中的「父」 table.The代碼選擇行顯示的「孩子」 table.It是是:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    self.nxt_obj_STMaster2ViewController=[[STMaster2ViewController alloc] initWithNibName:@"STMaster2ViewController" bundle:nil]; 
    self.nxt_obj_STMaster2ViewController.objCategory=[self.objects objectAtIndex:indexPath.row]; 
    self.nxt_obj_STMaster2ViewController.managedObjectContext=self.managedObjectContext; 
    self.nxt_obj_STMaster2ViewController.detailViewController=self.detailViewController; 
    self.nxt_obj_STMaster2ViewController.pre_STMasterViewController=self; 

    [tableView deselectRowAtIndexPath:indexPath animated:NO]; 

    [self.navigationController pushViewController:self.nxt_obj_STMaster2ViewController animated:YES]; 
} 

的viewDidLoad中的「孩子」文檔視圖控制器看起來是這樣的:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(button_refreshTapped:)]; 

    self.navigationItem.rightBarButtonItem=item; 

    UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"left-background.jpg"]]; 
    [tempImageView setFrame:self.tableView.frame]; 
    [self.tableView setBackgroundColor:[UIColor clearColor]]; 
    self.tableView.backgroundView = tempImageView; 

    [self startLoadingData:self.detailViewController.liveData]; 
} 
+0

請出示您正在使用,以顯示視圖控制器,該文件表中的代碼,您可能需要維持一個參考。視圖控制器。 – lnafziger

+0

@Inafziger: - 編輯的問題,更多的代碼 – user1550951

回答

1

所以,你在做什麼是每一次你打電話tableView:didSelectRowAtIndexPath:時間創建一個全新的閃亮的視圖控制器。相反,你應該只創建一次,在需要的時候重新顯示出來。我不知道你所有的邏輯的,因此你可能需要創建改變行時,一個新的(在這種情況下,你應該比較您的.objCategory以及看它是否與您的視圖控制器,你是對。推)

嘗試將其更改爲這樣:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (!self.nxt_obj_STMaster2ViewController) 
    { 
     self.nxt_obj_STMaster2ViewController=[[STMaster2ViewController alloc] initWithNibName:@"STMaster2ViewController" bundle:nil]; 
     self.nxt_obj_STMaster2ViewController.managedObjectContext=self.managedObjectContext; 
     self.nxt_obj_STMaster2ViewController.detailViewController=self.detailViewController; 
     self.nxt_obj_STMaster2ViewController.pre_STMasterViewController=self; 
    } 

    self.nxt_obj_STMaster2ViewController.objCategory=[self.objects objectAtIndex:indexPath.row]; 

    [tableView deselectRowAtIndexPath:indexPath animated:NO]; 

    [self.navigationController pushViewController:self.nxt_obj_STMaster2ViewController animated:YES]; 
} 
+0

謝謝!這解決了問題! – user1550951