[英]How to Open a UITableView from a UIButton
我正在使用具有许多单元格的自定义UICollectionView,每个单元格的底部附近都有一个按钮。 我想要做的是单击给定的单元格按钮时显示一个数字列表。 表列表将是简单的数字列表[1-n],其中n在单元的indexPath(即节和行)上变化。
我想弄清楚的是:
1)每当单击给定单元格的按钮时,如何打开uitableview? 2)我打开的uitableview是否必须占据整个屏幕?
基本上我不希望它占据整个屏幕(因为我被锁定在“风景”模式下,这看起来很奇怪),所以我想知道如何控制tableView的宽度和高度?
对不起,对于新手iOS问题,非常感谢!
( flipScore
按钮是我要从中打开uitableview的位置
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 4;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView
numberOfItemsInSection:(NSInteger)section
{
return _scoresList.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
MainCollectionViewCell *cell = [collectionView
dequeueReusableCellWithReuseIdentifier:@"ScoreCell"
forIndexPath:indexPath];
cell.layer.borderWidth=1.5f;
cell.layer.borderColor=[UIColor whiteColor].CGColor;
[[cell flipScore] addTarget:self action:@selector(flipScore:event:) forControlEvents:UIControlEventTouchUpInside];
long row = [indexPath row];
NSString *score;
NSInteger scoreVal;
//---------------------------------
switch (indexPath.section) {
case PLAYER_1:
score = [NSString stringWithString:_player_1_Scores[row]];
scoreVal = [score intValue];
if (scoreVal < 0) {
// if score negative, player did not make that hand
[cell.flipScore setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
NSString *substr = [score substringWithRange:NSMakeRange(1, ([score length]-1))];
cell.flipScore.titleLabel.font = [UIFont systemFontOfSize:24];
[cell.flipScore setTitle:substr forState:UIControlStateNormal];
}
else {
[cell.flipScore setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
cell.flipScore.titleLabel.font = [UIFont systemFontOfSize:38];
[cell.flipScore setTitle:score forState:UIControlStateNormal];
}
break;
case PLAYER_2:
score = [NSString stringWithString:_player_2_Scores[row]];
scoreVal = [score intValue];
if (scoreVal < 0) {
// if score negative, player did not make that hand
[cell.flipScore setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
NSString *substr = [score substringWithRange:NSMakeRange(1, ([score length]-1))];
cell.flipScore.titleLabel.font = [UIFont systemFontOfSize:24];
[cell.flipScore setTitle:substr forState:UIControlStateNormal];
}
else {
[cell.flipScore setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
cell.flipScore.titleLabel.font = [UIFont systemFontOfSize:38];
[cell.flipScore setTitle:score forState:UIControlStateNormal];
}
break;
case PLAYER_3:
score = [NSString stringWithString:_player_3_Scores[row]];
scoreVal = [score intValue];
if (scoreVal < 0) {
// if score negative, player did not make that hand
[cell.flipScore setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
NSString *substr = [score substringWithRange:NSMakeRange(1, ([score length]-1))];
cell.flipScore.titleLabel.font = [UIFont systemFontOfSize:24];
[cell.flipScore setTitle:substr forState:UIControlStateNormal];
}
else {
[cell.flipScore setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
cell.flipScore.titleLabel.font = [UIFont systemFontOfSize:38];
[cell.flipScore setTitle:score forState:UIControlStateNormal];
}
break;
case PLAYER_4:
score = [NSString stringWithString:_player_4_Scores[row]];
scoreVal = [score intValue];
if (scoreVal < 0) {
// if score negative, player did not make that hand
[cell.flipScore setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
NSString *substr = [score substringWithRange:NSMakeRange(1, ([score length]-1))];
cell.flipScore.titleLabel.font = [UIFont systemFontOfSize:24];
[cell.flipScore setTitle:substr forState:UIControlStateNormal];
}
else {
[cell.flipScore setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
cell.flipScore.titleLabel.font = [UIFont systemFontOfSize:38];
[cell.flipScore setTitle:score forState:UIControlStateNormal];
}
break;
}
return cell;
}
- (IBAction)flipScore:(id)sender event:(id)event {
NSSet *touches = [event allTouches];
UITouch *touch = [touches anyObject];
CGPoint currentTouchPosition = [touch locationInView:_collectionView];
NSIndexPath *indexPath = [_collectionView indexPathForItemAtPoint: currentTouchPosition];
NSLog(@"Flip Score: %ld, Row: %ld", (long)indexPath.section, (long)indexPath.row);
switch (indexPath.section) {
case PLAYER_1:
//TODO: open uiTableView with list of scores
break;
case PLAYER_2:
//TODO: open uiTableView with list of scores
break;
case PLAYER_3:
//TODO: open uiTableView with list of scores
break;
case PLAYER_4:
//TODO: open uiTableView with list of scores
break;
}
[_collectionView reloadData];
}
UITableView
不需要占用整个屏幕。 您可以设置表格视图的框架,并根据是否要显示它来设置hidden = YES
或=NO
。
您可以使用KGModal 。 您可以使用UITableViewController向您显示数据,然后使用
- (void)showWithContentViewController:(UIViewController *)contentViewController andAnimated:(BOOL)animated;
也不必担心方向,KGModal足够聪明,可以为您处理:)
希望这会起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.