2013-01-07 87 views
0

當我通過塊加載遠程內容時,我通過調用reloadData來更新UITableView。但是,我無法滾動此數據。我認爲這是因爲我已經聲明表中的行數是我的NSArray變量的長度,它將保存列表的內容。當這個被調用時,列表的計數爲零。我會假設通過在tableView上調用reloadData它會重新計算列表大小。 也許我錯過了一步。 感謝 這裏是我的代碼iOS - 無法在加載遠程內容後滾動UITableView

-(void)viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 
    dispatch_async(kBgQueue, ^{ 
     NSData* data = [NSData dataWithContentsOfURL: 
         [NSURL URLWithString: @"MYURL"]]; 
     [self performSelectorOnMainThread:@selector(fetchedData:) 
           withObject:data waitUntilDone:YES]; 

    }); 
} 
-(void) fetchedData:(NSData *)responseData 
{ 
    NSError* error; 
    id json = [NSJSONSerialization 
          JSONObjectWithData:responseData //1 
          options:kNilOptions 
          error:&error]; 

    self.dataList = json; 
    dispatch_async(dispatch_get_main_queue(), ^(void) { 
     [self.tableView reloadData]; 
    }); 
} 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return [self.dataList count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"SongCell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 

    // Configure the cell... 
    if([self.dataList count] > 0){ 
     NSDictionary *chartItem = [self.dataList objectAtIndex:indexPath.row]; 
     NSDictionary *song = [chartItem objectForKey:@"song"]; 
     cell.textLabel.text = [song objectForKey:@"title"]; 
    } 

    return cell; 
} 
+0

是否有足夠的數據導致滾動。當你觸摸它時桌子是否移動?前面是否有另一個視圖(清晰的顏色)可以攔截觸摸通話?你的代碼中沒有任何東西顯然是明顯的錯誤。表格是否顯示數據但不允許您滾動? – Bergasms

+0

我認爲伊娃發佈會有一些事情要做。如何定義'self.datalist'屬性?隨機錯誤=內存錯誤(經常) –

回答

0

這是現在的工作。 問題的原因是我已經添加了一個平移手勢的UITableView的

[self.view addGestureRecognizer:self.slidingViewController.panGesture]; 

這似乎與滾動桌子上干擾能力。希望這將有助於任何未來遇到此問題的人。

0

檢查您的json對象(因此self.dataList)是不是在異步調用結束零。如果是,那麼[self.dataList count]將返回0.

此外,請確保您正確設置self.dataList.dataSource

+0

感謝您的回覆。沒有JSON對象不是零。當數據出現在表中時,我的dataList對象正在被正確填充。它只是不滾動。那是什麼讓我相信表視圖認爲它有零行因此不啓用滾動 –

+0

你是否在表中看到任何有數據的行? – Macondo2Seattle

+0

是的,我可以看到大約10行半......其餘的消失在屏幕之外。內容正確顯示,只是不可滾動。 –