0

我是电话编程的新手。可以通过身体告诉我如何从一个视图转到故事板的第一个视图。下面的代码是 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 代码不起作用。

     #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。

4

1 回答 1

0

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

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

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

于 2013-03-18T09:07:55.790 回答