當我通過塊加載遠程內容時,我通過調用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;
}
是否有足夠的數據導致滾動。當你觸摸它時桌子是否移動?前面是否有另一個視圖(清晰的顏色)可以攔截觸摸通話?你的代碼中沒有任何東西顯然是明顯的錯誤。表格是否顯示數據但不允許您滾動? – Bergasms
我認爲伊娃發佈會有一些事情要做。如何定義'self.datalist'屬性?隨機錯誤=內存錯誤(經常) –