【发布时间】:2016-01-30 14:07:30
【问题描述】:
我想在表格视图上方添加一个按钮,而不是随着表格视图滚动。但是按钮不显示。有什么想法吗?
UIButton *refreshButton = [UIButton buttonWithType:UIButtonTypeCustom];
[refreshButton setImage:[UIImage imageNamed:@"refresh"] forState:UIControlStateNormal];
CGRect applicationFrame = [UIScreen mainScreen].bounds;
CGFloat screenWidth = CGRectGetWidth(applicationFrame);
CGFloat screenHeight = CGRectGetHeight(applicationFrame);
CGFloat buttonWidth = 40.0f;
CGFloat buttonHeight = 40.0f;
CGFloat spacing = 10.0f;
CGFloat buttonX = screenWidth - buttonWidth - spacing;
CGFloat buttonY = screenHeight - buttonHeight - spacing;
CGRect buttonFrame = CGRectMake(buttonX, buttonY, buttonWidth, buttonHeight);
refreshButton.frame = buttonFrame;
[refreshButton addTarget:self
action:@selector(clickRefreshButton)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:refreshButton];
提前致谢!
【问题讨论】:
-
将按钮添加到表头视图
-
仍然没有出现:(
-
如果将butotn添加到表头视图,它将被滚动到表视图。
-
您发布的代码不会将按钮添加到表格视图。它将按钮添加到视图中,由表视图覆盖。
-
我检查了视图层次,但没有按钮,没有被表格视图覆盖。另外,如果我将它作为子视图添加到表视图中,它也不会显示。
标签: ios objective-c uitableview uibutton