传递NSString在下一个ViewController中返回null [英] Passing NSString returning null in next ViewController

查看:83
本文介绍了传递NSString在下一个ViewController中返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 NSString从一个视图控制器传递到下一个。但是我似乎无法让它正常运行,我在尝试
之前设置了一个简单的 NSLog(@%@,myString); code> [vc2 setString:myString]; 打印正确的字符串,也在第二个viewController中,它返回null,所以我做错了。这是我的代码。

I am trying to pass an NSString from one view controller to the next. However I cannot seem to get it to function properly and I have set up a simple NSLog(@"%@", myString); before I try to [vc2 setString:myString]; which prints the correct string, and also in the second viewController and it is coming back as null so clearly I am doing something wrong. Here is my code.

第一个viewController

first viewController

#import "DetailController.h"
#import "City.h"
#import "VideoController.h"
#import "Helper.h"

@interface DetailController ()

@end

@implementation DetailController
@synthesize city, ClubName, Price, Vip, Promo, remain,p,deal,money,camera,cam,tweet,post;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{   
    [super viewDidLoad];
    UIImage *highlightedButtonImage = [UIImage imageNamed:@"twitter.png"]; 

    [Helper customizeBarButton:self.tweet image:highlightedButtonImage highlightedImage:highlightedButtonImage];

    UIImage *faceButtonImage = [UIImage imageNamed:@"facebook.png"]; 

    [Helper customizeBarButton:self.post image:faceButtonImage highlightedImage:faceButtonImage];


    // Do any additional setup after loading the view.
    UIFont *labelFont=[UIFont fontWithName:@"Deutsch Gothic" size:20.0];
    UIFont *myFont=[UIFont fontWithName:@"Deutsch Gothic" size:30.0];
    UIFont *titleFont=[UIFont fontWithName:@"Deutsch Gothic" size:40.0];
    NSString * name= self.city.clubName;
    NSString * line= self.city.clubLine;
    NSString * description= self.city.promo;
    NSString * price= self.city.price;


    remain.font=labelFont;
    remain.text=@"VIP Remaining :";
    p.font=labelFont;
    p.text=@"Price :";
    money.font=myFont;

    deal.font=labelFont;
    deal.text=@"Promotions :";

    ClubName.font=titleFont;
    ClubName.text=name;
    Vip.font=myFont;
    Vip.text=line;
    Price.font=myFont;
    Price.text=price;
    Promo.font=labelFont;
    Promo.text=description;
 }

- (IBAction)play:(id)sender 
{
     VideoController *vc2 = [[VideoController alloc]initWithNibName:@"ViewController" bundle:nil];
    [vc2 setCam:self.city.camera];
    [self.navigationController pushViewController:vc2 animated:YES];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end

第二个ViewController

Second ViewController

#import "VideoController.h"
#import "City.h"

@interface VideoController ()

@end

@implementation VideoController
@synthesize webView,city,cam;



- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{  
    NSLog(@"%@", cam);
    image.animationImages = [NSArray arrayWithObjects:
                         [UIImage imageNamed:@"32.tiff"],
                         [UIImage imageNamed:@"31.tiff"],
                         [UIImage imageNamed:@"30.tiff"],
                         [UIImage imageNamed:@"29.tiff"],
                         [UIImage imageNamed:@"28.tiff"],
                         [UIImage imageNamed:@"27.tiff"],
                         [UIImage imageNamed:@"26.tiff"],
                         [UIImage imageNamed:@"25.tiff"],
                         [UIImage imageNamed:@"24.tiff"],
                         [UIImage imageNamed:@"23.tiff"],
                         [UIImage imageNamed:@"22.tiff"],
                         [UIImage imageNamed:@"21.tiff"],
                         [UIImage imageNamed:@"20.tiff"],
                         [UIImage imageNamed:@"19.tiff"],
                         [UIImage imageNamed:@"18.tiff"],
                         [UIImage imageNamed:@"17.tiff"],
                         [UIImage imageNamed:@"16.tiff"],
                         [UIImage imageNamed:@"15.tiff"],
                         [UIImage imageNamed:@"14.tiff"],
                         [UIImage imageNamed:@"13.tiff"],
                         [UIImage imageNamed:@"12.tiff"],
                         [UIImage imageNamed:@"11.tiff"],
                         [UIImage imageNamed:@"10.tiff"],
                         [UIImage imageNamed:@"9.tiff"],
                         [UIImage imageNamed:@"8.tiff"],
                         [UIImage imageNamed:@"7.tiff"],
                         [UIImage imageNamed:@"6.tiff"],
                         [UIImage imageNamed:@"5.tiff"],
                         [UIImage imageNamed:@"4.tiff"],
                         [UIImage imageNamed:@"3.tiff"],
                         [UIImage imageNamed:@"2.tiff"],
                         [UIImage imageNamed:@"1.tiff"],nil];

    [image setAnimationRepeatCount:1];
    image.animationDuration = 10.0;
    [image startAnimating];
    [super viewDidLoad];
}

-(void)yourMethod
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end


推荐答案

我猜测你没有推动第二个VC,你在故事板中使用了一个segue从第一个到第二个。

I'm guessing from the absence of a push to the second VC that you're using a segue in a storyboard to go from the first to the second.

如果这是正确的,那么你应该在第一个视图控制器中做一些滑动...

If this is correct then you should do something glide this in the first view controller...

- (void)prepareForSegue:(UIStoryboardSegue *)segue
{
    VideoController *vc2 = segue.destinationViewController;

    [vc2 setCam:self.city.camera];
}

并在 viewDidLoad中删除处理VC2的行

这篇关于传递NSString在下一个ViewController中返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆