【发布时间】:2016-05-02 14:19:06
【问题描述】:
我有一个 tableView,它在导航栏下总是有一个空白区域,在我在视图层次结构中调试后,我发现 tableView 的大小与 tableViewWrapperView 的大小不同。有什么想法吗?
以下是我遇到问题的 tableViewController 的代码:
#import "BBTCampusInfoTableViewController.h"
#import "BBTCampusInfoManager.h"
#import "BBTCampusInfoTableViewCell.h"
#import <UIImageView+WebCache.h>
@interface BBTCampusInfoTableViewController ()
@end
@implementation BBTCampusInfoTableViewController
extern NSString * campusInfoNotificationName;
- (void)viewWillAppear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveCampusInfoNotification) name:campusInfoNotificationName object:nil];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.automaticallyAdjustsScrollViewInsets = NO;
//self.tableView.contentInset = UIEdgeInsetsZero;
//Retrive all campus infos
[[BBTCampusInfoManager sharedInfoManager] retriveData:@""];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [[BBTCampusInfoManager sharedInfoManager].infoArray count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 140.0f;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 0.5;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
return view;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *cellIdentifier = @"infoCell";
BBTCampusInfoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell)
{
cell = [[BBTCampusInfoTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
NSArray *infoArray = [BBTCampusInfoManager sharedInfoManager].infoArray;
[cell setCellContentDictionary:infoArray[indexPath.row]];
[cell setNeedsUpdateConstraints];
[cell updateConstraintsIfNeeded];
return cell;
}
- (void)didReceiveCampusInfoNotification
{
NSLog(@"Did receive campus info notification");
[self.tableView reloadData];
}
【问题讨论】:
-
我读过那个,但他的方法对我不起作用。
-
@Caeser,因为您显然已经尝试了所有方法(并且没有任何方法对您有用),请将链接添加到您已阅读且对您不起作用的方法。否则人们会不断重复惯用的方法,浪费大家的时间。
标签: ios objective-c uitableview