Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何从UIButton打开UITableView_Ios_Objective C_Ios6_Storyboard - Fatal编程技术网

Ios 如何从UIButton打开UITableView

Ios 如何从UIButton打开UITableView,ios,objective-c,ios6,storyboard,Ios,Objective C,Ios6,Storyboard,我使用的是一个自定义UICollectionView,它有许多单元格,每个单元格底部都有一个按钮。我想做的是在单击给定的单元格按钮时显示一个数字列表。表列表将是一个简单的数字列表[1-n],其中n在单元格的indexPath(即节和行)上变化 我想弄明白的是: 1) 如何在单击给定单元格的按钮时打开uitableview? 2) 我打开的uitableview是否必须占据整个屏幕 基本上,我不希望它占据整个屏幕(因为我被锁定在横向模式,这看起来很奇怪),所以我想知道如何控制tableView的宽

我使用的是一个自定义UICollectionView,它有许多单元格,每个单元格底部都有一个按钮。我想做的是在单击给定的单元格按钮时显示一个数字列表。表列表将是一个简单的数字列表[1-n],其中n在单元格的indexPath(即节和行)上变化

我想弄明白的是:

1) 如何在单击给定单元格的按钮时打开uitableview? 2) 我打开的uitableview是否必须占据整个屏幕

基本上,我不希望它占据整个屏幕(因为我被锁定在横向模式,这看起来很奇怪),所以我想知道如何控制tableView的宽度和高度

对于noob 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];
}
-(NSInteger)SectionsInCollectionView:(UICollectionView*)collectionView
{
返回4;
}
-(NSInteger)collectionView:(UICollectionView*)collectionView
节中的项目编号:(NSInteger)节
{
返回_scoresList.count;
}
-(UICollectionViewCell*)collectionView:(UICollectionView*)collectionView cellForItemAtIndexPath:(NSIndexPath*)indexPath
{
MainCollectionViewCell*单元格=[collectionView
dequeueReusableCellWithReuseIdentifier:@“ScoreCell”
forIndexPath:indexPath];
单元层边界宽度=1.5f;
cell.layer.borderColor=[UIColor whiteColor].CGColor;
[[cell flipScore]添加目标:自我操作:@selector(flipScore:event:)forControlEvents:UIControlEventTouchUpInside];
长行=[indexPath行];
NSString*分数;
NSInteger scoreVal;
//---------------------------------
开关(indexPath.section){
案例1:
分数=[NSString STRING WITHSTRING:_玩家_1_分数[行]];
scoreVal=[score intValue];
if(scoreVal<0){
//若得分为负数,那个么球员并没有做出那个手牌
[cell.flipScore setTitleColor:[UIColor redColor]用于状态:UIControlStateNormal];
NSString*substr=[score substringWithRange:NSMakeRange(1,([score length]-1));
cell.flipScore.titleLabel.font=[UIFont systemFontOfSize:24];
[cell.flipScore setTitle:substr for state:UIControlStateNormal];
}
否则{
[cell.flipScore setTitleColor:[UIColor whiteColor]用于状态:UIControlStateNormal];
cell.flipScore.titleLabel.font=[UIFont systemFontOfSize:38];
[cell.flipScore setTitle:score for状态:uicontrol状态正常];
}
打破
案例2:
分数=[NSString STRING WITHSTRING:_玩家_2_分数[行]];
scoreVal=[score intValue];
if(scoreVal<0){
//若得分为负数,那个么球员并没有做出那个手牌
[cell.flipScore setTitleColor:[UIColor redColor]用于状态:UIControlStateNormal];
NSString*substr=[score substringWithRange:NSMakeRange(1,([score length]-1));
cell.flipScore.titleLabel.font=[UIFont systemFontOfSize:24];
[cell.flipScore setTitle:substr for state:UIControlStateNormal];
}
否则{
[cell.flipScore setTitleColor:[UIColor whiteColor]用于状态:UIControlStateNormal];
cell.flipScore.titleLabel.font=[UIFont systemFontOfSize:38];
[cell.flipScore setTitle:score for状态:uicontrol状态正常];
}
打破
案例3:
分数=[NSString STRING WITHSTRING:_玩家_3_分数[行]];
scoreVal=[score intValue];
if(scoreVal<0){
//若得分为负数,那个么球员并没有做出那个手牌
[cell.flipScore setTitleColor:[UIColor redColor]用于状态:UIControlStateNormal];
NSString*substr=[score substringWithRange:NSMakeRange(1,([score length]-1));
cell.flipScore.titleLabel.font=[UIFont systemFontOfSize:24];
[cell.flipScore setTitle:substr for state:UIControlStateNormal];
}
否则{
[cell.flipScore setTitleColor:[UIColor whiteColor]用于状态:UIControlStateNormal];
cell.flipScore.titleLabel.font=[UIFont systemFontOfSize:38];
[cell.flipScore setTitle:score for状态:uicontrol状态正常];
}
打破
案例4:
分数=[NSString STRING WITHSTRING:_玩家_4_分数[行]];
scoreVal=[score intValue];
if(scoreVal<0){
//若得分为负数,那个么球员并没有做出那个手牌
[cell.flipScore setTitleColor:[UIColor redColor]用于状态:UIControlStateNormal];
NSString*substr=[score substringWithRange:NSMakeRange(1,([score length]-1));
cell.flipScore.titleLabel.font=[UIFont systemFontOfSize:24];
[cell.flipScore setTitle:substr for state:UIControlStateNormal];
}
否则{
[cell.flipScore setTitleColor:[UIColor whiteColor]用于状态:UIControlStateNormal];
cell.flipScore.titleLabel.font=[UIFont systemFontOfSize:38];
[cell.flipScore setTitle:score for状态:uicontrol状态正常];
}
打破
}
返回单元;
}
-(iAction)flipScore:(id)发送方事件:(id)事件{
NSSet*touchs=[event alltouchs];
UITouch*touch=[触摸任何对象];
CGPoint currentTouchPosition=[touch locationInView:_collectionView];
NSIndexPath*indexPath=[\u collectionView indexPathForItemAtPoint:currentTouchPosition];
NSLog(@“翻转分数:%ld,行:%ld”,(长)indexPath.section,(长)indexPath.Row);
开关(indexPath.section){
案例1:
//TODO:使用lis打开uiTableView
- (void)showWithContentViewController:(UIViewController *)contentViewController andAnimated:(BOOL)animated;