我的View Controller中有一个UITableView,数据加载到表中,但我根本无法滚动它。我已经尝试了很多方法来解决它但无法找到解决方案。我也使用SWRevealViewController作为侧边栏菜单,但我认为这不会影响滚动功能吗?
以下是我的View Controller中的代码
- (void)viewDidLoad {
[super viewDidLoad];
SWRevealViewController *revealViewController = self.revealViewController;
if ( revealViewController )
{
[self.barButton setTarget: self.revealViewController];
[self.barButton setAction: @selector( revealToggle: )];
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
}
_providerName = [NSMutableArray arrayWithObjects:
@"Food Bank of Alaska",
@"Community Food Bank of Central Alabama",
@"Food Bank of North Alabama",
@"Montgomery Area Food Bank",
@"Feeding the Gulf Coast",
@"Northwest Arkansas Food Bank",
@"River Valley Regional Food Bank",
@"Food Bank of Northeast Arkansas",
@"Arkansas Foodbank",
@"Harvest Texarkana Regional Food Bank",
@"United Food Bank",
@"St. Mary's Food Bank Alliance",
... (there's more data here)
nil];
_providerId = [NSMutableArray arrayWithObjects:@"0", @"0", @"0",
@"0", @"0", @"0",
@"0", @"0", @"0",
..... (there's more data here)
nil];
self.navigationItem.title = @"Call History";
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.tableView reloadData];
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
// Remove seperator inset
if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsZero];
}
// Prevent the cell from inheriting the Table View's margin settings
if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
[cell setPreservesSuperviewLayoutMargins:NO];
}
// Explictly set your cell's layout margins
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.providerName count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"moneyItemRow";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.textLabel.text = [self.providerName objectAtIndex:indexPath.row];
cell.detailTextLabel.text =[self.providerId objectAtIndex:indexPath.row];
return cell;
}
这是我的视图控制器的图片,显示表格视图不在任何边缘附近,因此没有任何重叠
答案 0 :(得分:0)
//删除此代码
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
// Remove seperator inset
if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsZero];
}
// Prevent the cell from inheriting the Table View's margin settings
if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
[cell setPreservesSuperviewLayoutMargins:NO];
}
// Explictly set your cell's layout margins
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}
答案 1 :(得分:0)
我将为您提供表格视图滚动的完整答案