我一直在StackOverflow很多不同的問題,但我只是無法弄清楚這裏有什麼問題。 我有一個視圖控制器,從JSON接收數據,創建一個數組,然後,它建立一個具有固定高度的UITableView。 問題是我無法滾動到底部。它只是反彈回來。UITableView滾動返回頂部
- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellIdentifier = @"SettingsCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
[cell.detailTextLabel setNumberOfLines:2];
NSDictionary* place = [_placesData objectAtIndex:indexPath.row];
[cell.textLabel setText:[place valueForKey:@"nome"]];
[cell.detailTextLabel setText:[place valueForKey:@"endereco"]];
[cell.detailTextLabel setLineBreakMode:NSLineBreakByWordWrapping];
[cell.detailTextLabel sizeToFit];
UIImage* originalImage = [UIImage imageNamed:@"encontre.png"];
UIImage* resized = [UIImage imageWithCGImage:[originalImage CGImage]scale:(originalImage.scale * 1.8) orientation:(originalImage.imageOrientation)];
cell.imageView.image=resized;
cell.textLabel.font = [UIFont fontWithName:@"GillSans" size:17];
cell.textLabel.textColor = [UIColor whiteColor];
cell.detailTextLabel.font = [UIFont fontWithName:@"GillSans-Light" size:17];
self.tableView.scrollEnabled=YES;
self.tableView.bounces=YES;
[self.tableView setAlwaysBounceVertical:YES];
return cell;
}
我不知道該怎麼辦。已嘗試手動設置contentSize.height
,強制bounces
和scrollEnabled
幾乎將視圖控制器上的一段代碼翻轉過來。
問候。
那些最後三行之前'return'(設置滾動和彈跳行爲的那些)不屬於這種方法。最好把它們放在你的'UITableViewController'子類的'init'方法中,因爲這些屬性只需要設置一次。 – bdesham
假設您正在使用界面生成器來處理主佈局?所有這些自動調整屬性都設置正確嗎?除了@ bdesham的評論(這仍然不會導致您所看到的問題),此方法中的任何內容都不會顯得太糟糕。 – jterry
當然看起來像那個tableview框架正在可見的視圖下方。 (比你看到的要大得多)你可以啓用側滾動條嗎?當你滾動(拉起來)時,你會看到側滾動條移動到可見的tableview框架之外 - 這意味着框架太大了。你有任何scrollViewDidScroll委託方法?另一種選擇是填充tableview,比如100條記錄。然後看看它是否允許滾動並且不反彈。 –