【发布时间】:2019-02-21 04:20:33
【问题描述】:
我有一个包含两个标签、一个表格视图和按钮的弹出视图。我创建了一个 ViewController,如Display UIViewController as Popup in iPhone 所述。
我现在的特殊要求是,并不是所有情况下都需要 tableview,所以我试图隐藏它并期望降低 Popup-View 的高度。但我总是得到相同的高度。我也尝试使用 UIStackView,但是在隐藏 tableview 的情况下视图的高度没有改变。
在两种高度情况下,我还需要将视图置于显示器的中心。
@interface AuthorizationMessageViewController ()
@property (weak, nonatomic) IBOutlet UIView *messageView;
@property (weak, nonatomic) IBOutlet UILabel *titelLabel;
@property (weak, nonatomic) IBOutlet UILabel *detailsLabel;
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UIButton *okButton;
- (IBAction)okButtonTouchUp:(id)sender;
@end
@implementation AuthorizationMessageViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.messageView.layer.cornerRadius = 5;
self.messageView.layer.masksToBounds = YES;
self.messageView.backgroundColor = COLOR_BACKGROUND_WHITE;
self.messageView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin;
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
self.tableView.separatorColor = [UIColor clearColor];
self.tableView.backgroundColor = COLOR_BACKGROUND_WHITE;
self.titelLabel.text = WHLocalizedString(@"EventHeaderAuthorization", nil);
[self setupView];
}
- (void)setupView
{
NSString *ns_messageText;
ns_messageText = @"test";
if (YES)
{
ns_messageText = @"Hide"
[self.tableView setHidden:YES];
}
else
{
ns_messageText = @"No Hide"
[self.tableView setHidden:NO];
}
self.detailsLabel.text = ns_messageText;
self.detailsLabel.textColor = COLOR_TEXT_GREY_KEY;
self.detailsLabel.numberOfLines = 0;
[self.detailsLabel sizeToFit];
}
#pragma mark - Table view data source
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 7;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 21;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"testCell"];
UILabel *weekDayLabel = (UILabel *)[cell viewWithTag:10];
weekDayLabel.text = @"weekday";
weekDayLabel.textColor = COLOR_TEXT_GREY_KEY;
weekDayLabel.font = FONT_LIGHT_SIZE_15;
UILabel *testLabel = (UILabel *)[cell viewWithTag:11];
testLabel = @"testLabel"
testLabel = COLOR_TEXT_GREY_KEY;
testLabel = FONT_LIGHT_SIZE_15;
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
return cell;
}
我希望有人对此有解决方案或想法。
【问题讨论】:
-
提供试用码。
-
试试这个
tableView.isHidden = true和tableView.frame = CGRect.zero。
标签: ios objective-c uiviewcontroller