我试图根据标题UISegmentedControl
中的选择调整部分标题的大小。 出于某种原因,它只是不想工作。我已经尝试过[self.tableView beginUpdates];
和[self.tableView endUpdates];
之前,周围和之后的变化高度代码..但它只是很奇怪。调整UITableViewController中部分标题的大小无法正常工作
我知道它隐藏和显示内容,但它似乎为视图分配不同的高度,即使认为标题的大小应该更小。
这是发生了什么: https://dl.dropboxusercontent.com/u/3077127/Problem3.mov
这是我的代码:
typedef enum {
kSearchTypeFrom = 0,
kSearchTypeTo
} kSearchType;
@interface MainVC()
@property (nonatomic, strong) FilterVC *filterView;
@property (nonatomic, assign) kSearchType searchType;
@end
@implementation MainVC
@synthesize filterView = _filterView;
@synthesize searchType = _searchType;
[...]
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
self.searchType = kSearchTypeFrom;
[self.tableView beginUpdates];
[self.tableView endUpdates];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
}
// Configure the cell...
[cell.detailTextLabel setText:@"Test"];
return cell;
}
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
if (!self.filterView) {
self.filterView = [[FilterVC alloc] init];
[self.filterView.view setBackgroundColor:self.navigationController.navigationBar.barTintColor];
}
[self.filterView.segment setSelectedSegmentIndex:self.searchType];
[self.filterView.segment addTarget:self action:@selector(didChangeSegmentSelection:) forControlEvents:UIControlEventValueChanged];
return self.filterView.view;
}
- (float)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if (self.searchType == kSearchTypeFrom)
{
return 130;
}
else {
return 100;
}
}
#pragma mark - Height change table section
- (void)didChangeSegmentSelection:(UISegmentedControl*)segment
{
[self.tableView beginUpdates];
self.searchType = segment.selectedSegmentIndex;
NSLog(@"Selected: %d", segment.selectedSegmentIndex);
if (segment.selectedSegmentIndex == 0)
{
[self.filterView.changeToText setHidden:NO];
[self.filterView.changeToButton setHidden:NO];
[self.filterView.fromButton setUserInteractionEnabled:NO];
}
else {
[self.filterView.changeToText setHidden:YES];
[self.filterView.changeToButton setHidden:YES];
[self.filterView.fromButton setUserInteractionEnabled:YES];
}
[self.tableView endUpdates];
[self.filterView.view needsUpdateConstraints];
}
[...]
的FilterVC
类不过是包含以下内容的UIViewController的更多:
是什么我做错了吗?
你的Dropbox的链接似乎并不有效。 –
对不起...假期项目..和度假村的无线网络连接不好。没有上传。我现在正在尝试。 –
@TimothyMoose文件已上传,应该可以工作。感谢您的注意。 –