自定义表格部分页脚视图 - 标签不可见(Custom table section footer view - label not visible)
我在Xcode中使用单个UITableViewController创建了一个新的单视图项目(使用storyboard)。 这是设置代码:
- (void)viewDidLoad { [super viewDidLoad]; _footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 44, 44)]; _footerView.autoresizingMask = UIViewAutoresizingFlexibleWidth; UILabel *l = [[UILabel alloc] initWithFrame:CGRectMake(60, 0, 44, 44)]; l.text = @"Label Label Label Label Label Label Label Label Label"; l.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth; l.backgroundColor = [UIColor clearColor]; [_footerView addSubview:l]; _footerView.backgroundColor = [UIColor lightGrayColor]; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 1; } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return _footerView.frame.size.height; } - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { return _footerView; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { return [tableView dequeueReusableCellWithIdentifier:@"Cell"]; }
我希望自定义表格页脚视图中的标签在x = 60处绘制,但是当我运行项目时,首先标签是不可见的(纵向,屏幕附加)。 然后,如果我旋转一次,它就会变得可见,如果我旋转回到肖像,它就是可见的。
我错过了什么?
I created a new Single-view project (using storyboard) in Xcode with a single UITableViewController. Here is the setup code:
- (void)viewDidLoad { [super viewDidLoad]; _footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 44, 44)]; _footerView.autoresizingMask = UIViewAutoresizingFlexibleWidth; UILabel *l = [[UILabel alloc] initWithFrame:CGRectMake(60, 0, 44, 44)]; l.text = @"Label Label Label Label Label Label Label Label Label"; l.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth; l.backgroundColor = [UIColor clearColor]; [_footerView addSubview:l]; _footerView.backgroundColor = [UIColor lightGrayColor]; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 1; } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return _footerView.frame.size.height; } - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { return _footerView; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { return [tableView dequeueReusableCellWithIdentifier:@"Cell"]; }
I want the label in the custom table footer view to be drawn at x = 60, but when I run the project, at first the label is invisible (in portrait, screen attached). Then if I rotate once, it becomes visible and if I rotate back to portrait it's visible.
What am I missing?
原文:https://stackoverflow.com/questions/14399122
最满意答案
这是一次尝试:
head(rbind(x, diag(y)),-1)
这基本上从
y
创建一个方阵,其中diag
onal上的值,通过rbind
-ingx
向下推一行,然后从新创建的矩阵的底部删除额外的行。或者使用
row
和col
进行一些创意索引也可以做到:m <- matrix(0,nrow=7,ncol=7) m[row(m)-col(m)==1] <- head(y,-1) m[1,] <- x
两人都回归:
# [,1] [,2] [,3] [,4] [,5] [,6] [,7] #[1,] 0.00 0.0 0.0 0.0 0.0 0.5 0.5 #[2,] 0.75 0.0 0.0 0.0 0.0 0.0 0.0 #[3,] 0.00 0.8 0.0 0.0 0.0 0.0 0.0 #[4,] 0.00 0.0 0.8 0.0 0.0 0.0 0.0 #[5,] 0.00 0.0 0.0 0.9 0.0 0.0 0.0 #[6,] 0.00 0.0 0.0 0.0 0.6 0.0 0.0 #[7,] 0.00 0.0 0.0 0.0 0.0 0.8 0.0
Here's an attempt all in one go:
head(rbind(x, diag(y)),-1)
This basically creates a square matrix from
y
with the values on thediag
onal, pushes it down by one row byrbind
-ingx
, then drops the extra row from the bottom of the newly created matrix.Or a bit of creative indexing using
row
andcol
can do it too:m <- matrix(0,nrow=7,ncol=7) m[row(m)-col(m)==1] <- head(y,-1) m[1,] <- x
Both returning:
# [,1] [,2] [,3] [,4] [,5] [,6] [,7] #[1,] 0.00 0.0 0.0 0.0 0.0 0.5 0.5 #[2,] 0.75 0.0 0.0 0.0 0.0 0.0 0.0 #[3,] 0.00 0.8 0.0 0.0 0.0 0.0 0.0 #[4,] 0.00 0.0 0.8 0.0 0.0 0.0 0.0 #[5,] 0.00 0.0 0.0 0.9 0.0 0.0 0.0 #[6,] 0.00 0.0 0.0 0.0 0.6 0.0 0.0 #[7,] 0.00 0.0 0.0 0.0 0.0 0.8 0.0
相关问答
更多-
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
只需使用matrix : matrix(vec,nrow = 7,ncol = 7) 使用matrix而不是简单地改变维度属性的一个优点是,Gavin指出,您可以使用矩阵中的byrow参数指定矩阵是由行还是列填充。 Just use matrix: matrix(vec,nrow = 7,ncol = 7) One advantage of using matrix rather than simply altering the dimension attribute as Gavin points o ...
-
这是一次尝试: head(rbind(x, diag(y)),-1) 这基本上从y创建一个方阵,其中diag onal上的值,通过rbind -ing x向下推一行,然后从新创建的矩阵的底部删除额外的行。 或者使用row和col进行一些创意索引也可以做到: m <- matrix(0,nrow=7,ncol=7) m[row(m)-col(m)==1] <- head(y,-1) m[1,] <- x 两人都回归: # [,1] [,2] [,3] [,4] [,5] [,6] [,7] #[1 ...
-
如何比较r中的两列矩阵并在新向量中输出列名(How to compare two columns of matrix in r and output the column name in a new vector)[2023-04-13]
你需要if / else的矢量化版本。 矩阵版本: ifelse(data[,2] > data[,1], "second", "first") You need the vectorized version of if/else. The matrix version: ifelse(data[,2] > data[,1], "second", "first") -
使用逻辑操作 sym_mat <- (mat | t(mat)) * 1 @ chinsoon12的建议非常好。 sym_mat <- +(mat | t(mat)) Using logical operations sym_mat <- (mat | t(mat)) * 1 @chinsoon12's suggestion is quite nice. sym_mat <- +(mat | t(mat))
-
根据R中对角线的值删除矩阵中的行和列(Deleting rows and columns in matrix based on values in diagonal in R)[2024-03-14]
使用diag函数和逻辑比较<和[子集运算符... idx <- ! diag(m) < 5 m <- m[ idx , idx ] 例如 m # x1 x2 x3 x4 #x1 13 15 12 25 #x2 23 4 23 34 #x3 21 11 1 11 #x4 11 22 23 33 idx <- ! diag(m) < 5 m <- m[ idx , idx ] m # x1 x4 #x1 13 25 #x4 11 33 Use the diag function an ... -
我希望我能正确理解这个问题。 我们假设这是您的数据: states = c('Ca', 'Ar', 'Wi', 'Ca', 'Wa', 'Wa', 'Wa') 你的zero_mat和它的列名是这样定义的: states_uniq = unique(states) zero_mat = matrix(0, ncol=length(states_uniq), nrow=length(states)) colnames(zero_mat) = states_uniq ## Ca Ar Wi Wa # ...
-
通过直到对角线的行计算矢量和矩阵的累积和(Calculate cumulative sum of vector and matrix by rows up to diagonal)[2023-12-22]
您可以尝试使用colSums ,即 colSums(y *t(x)) #[1] 3.0 6.3 34.6 You can try with colSums, i.e. colSums(y *t(x)) #[1] 3.0 6.3 34.6 -
R>oop*drop(oo) [,1] [,2] [,3] [1,] 1 2 3 [2,] 8 10 12 [3,] 21 24 27 R>oop*drop(oo) [,1] [,2] [,3] [1,] 1 2 3 [2,] 8 10 12 [3,] 21 24 27
-
从非方形矩阵中获取所有可能对角线的最快但迄今为止最神秘的解决方案是将矩阵视为向量并简单地构造id向量以供选择。 最后,如果需要,您可以将其转换回矩阵。 以下功能可以: exdiag <- function(mat){ NR <- nrow(mat) NC <- ncol(mat) smalldim <- min(NC,NR) if(NC > NR){ id <- seq_len(NR) + seq.int(0,NR-1)*NR + rep(seq.int( ...