【问题标题】:How to go from one view to first view of storyboard in iphone如何在iphone中从一个视图转到故事板的第一个视图
【发布时间】:2013-03-18 08:38:39
【问题描述】:

我是电话编程的新手。可以告诉我如何从一个视图转到故事板的第一个视图。下面的代码是 firstviewcontroller.m 类,我在里面有一个按钮,我写了一些我想要的动作从 firstviewcontroller 转到 stroyboard 的第一个视图。

 #import"firstviewcontroller.h"  
    -(IBAction)show:(id)sender
    {
     UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
     LXCollectionViewController *Controller = [storyboard  instantiateViewControllerWithIdentifier:@"Controller "];
      [self presentModalViewController:loginController animated:YES];

    }

下面的代码是 storybord firstview 代码我如何从这个 xib 视图转到 storyborad view.programatically.above code is not working.

     #import "LXCollectionViewController.h"
        #import "PlayingCard.h"
        #import "PlayingCardCell.h"
        @implementation LXCollectionViewController
        - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
        {
            self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
            if (self) {
                // Custom initialization
            }
            return self;
        }
        - (void)awakeFromNib {
            [super awakeFromNib];
            self.deck = [self constructsDeck];
        }

        - (NSMutableArray *)constructsDeck {
            NSMutableArray *theDeck = [NSMutableArray arrayWithCapacity:52];
            for (NSInteger theRank = 1; theRank <= 13; theRank++) {
                // Spade
                {
                    PlayingCard *thePlayingCard = [[PlayingCard alloc] init];
                    thePlayingCard.suit = PlayingCardSuitSpade;
                    thePlayingCard.rank = theRank;
                    [theDeck addObject:thePlayingCard];
                }
            }
            return theDeck;
        }

        - (void)viewDidLoad {
          //  NSLog(@"%@",theDeck);
            [super viewDidLoad];
            // Do any additional setup after loading the view.
        }
        #pragma mark - UICollectionViewDataSource methods

        - (NSInteger)collectionView:(UICollectionView *)theCollectionView numberOfItemsInSection:(NSInteger)theSectionIndex {
            switch (theSectionIndex) {
                case 0: {
                    return [[self valueForKeyPath:@"deck.@count"] integerValue];
                } break;
                default: {
                    return 0;
                } break;
            }
        }

 - (UICollectionViewCell *)collectionView:(UICollectionView *)theCollectionView cellForItemAtIndexPath:(NSIndexPath *)theIndexPath {
                NSInteger theSectionIndex = theIndexPath.section;
                NSInteger theItemIndex = theIndexPath.item;
                switch (theSectionIndex) {
                    case 0: {
                        PlayingCard *thePlayingCard = [self.deck objectAtIndex:theItemIndex];
                        PlayingCardCell *thePlayingCardCell = [theCollectionView dequeueReusableCellWithReuseIdentifier:@"PlayingCardCell" forIndexPath:theIndexPath];
                        thePlayingCardCell.playingCard = thePlayingCard;
                        return thePlayingCardCell;
                    } break;
                    default: {
                        return nil;
                    } break;
                }
            }

            #pragma mark - LXReorderableCollectionViewDelegateFlowLayout methods

            - (void)collectionView:(UICollectionView *)theCollectionView layout:(UICollectionViewLayout *)theLayout itemAtIndexPath:(NSIndexPath *)theFromIndexPath willMoveToIndexPath:(NSIndexPath *)theToIndexPath {
                id theFromItem = [self.deck objectAtIndex:theFromIndexPath.item];
                [self.deck removeObjectAtIndex:theFromIndexPath.item];
                [self.deck insertObject:theFromItem atIndex:theToIndexPath.item];
            }

IBAction 中的上述代码不起作用。请告诉我如何将表单 xib 连接到情节提要的 firstview。

【问题讨论】:

    标签: iphone ios


    【解决方案1】:

    如果您使用的是 iOS sdk 6.1,请尝试以下一种,因为 presentViewController 已弃用

    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    LXCollectionViewController *objController = [sb instantiateViewControllerWithIdentifier:@"Controller"];
    [objController setModalPresentationStyle:UIModalPresentationFullScreen];
    [self presentViewController:objController animated:YES completion:nil];
    

    并确保您在情节提要的 viewControllers 中指定了标识符

    【讨论】:

    • 感谢您提供重播。现在它在故事板视图控制器中的指定标识符也不起作用。实际上我在故事板中使用 collectionview 控制器。
    猜你喜欢
    • 2013-02-03
    • 2017-12-15
    • 1970-01-01
    • 2013-06-16
    • 2012-04-21
    • 1970-01-01
    • 2013-09-17
    • 2011-12-01
    • 1970-01-01
    相关资源
    最近更新 更多