如何在iphone中从一个视图转到故事板的第一个视图

Posted

技术标签:

【中文标题】如何在iphone中从一个视图转到故事板的第一个视图【英文标题】:How to go from one view to first view of storyboard in 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。

【问题讨论】:

【参考方案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 控制器。

以上是关于如何在iphone中从一个视图转到故事板的第一个视图的主要内容,如果未能解决你的问题,请参考以下文章

访问视图来自另一个类的Controller元素

用于通用故事板的 PSD

如何在 swift 中从情节提要中的 didSelectRowAt indexPath 打开视图标签栏控制器?

如何回到不同故事板的先前视图控制器?

从另一个类访问 viewController 元素

如何在 XCode 中预览故事板的不同视图控制器