我使用的是自定义UICollectionView,它有许多单元格,每个单元格底部附近都有一个按钮。我想要做的是在单击给定单元格按钮时显示数字表格列表。表格列表将是一个简单的数字列表[1-n],其中n在单元格的indexPath(即节和行)上有所不同。
我想弄清楚的是:
1)如果单击给定单元格的按钮,如何打开uitableview? 2)我打开的uitableview是否必须占用整个屏幕?
基本上我不希望它占用整个屏幕(因为我被锁定在横向模式下,这看起来很奇怪)所以我想知道如何控制tableView的宽度和高度?
对不起iOS问题抱歉,感谢您的帮助!
(flipScore
按钮是我想从
-(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];
}
答案 0 :(得分:0)
UITableView
不需要占用整个屏幕。
您可以设置tableview的框架,并根据您是否要显示它来设置hidden = YES
或=NO
。
答案 1 :(得分:0)
您可以使用KGModal。您可以使用UITableViewController向您显示数据,然后使用
添加您的tableview- (void)showWithContentViewController:(UIViewController *)contentViewController andAnimated:(BOOL)animated;
也不用担心迎新,KGModal足够聪明,可以为你处理:)
希望这会奏效。