无法将NSString传递给DetailViewController

时间:2013-09-17 10:43:55

标签: ios objective-c cocoa-touch nsstring

MasterViewController.h

NSString *quality;

MasterViewController.m

#import DetailViewController.h

-(void)viewDidLoad {
    quality = [NSString stringWithFormat:@"string to pass"];

    ...

}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"showDetail"]) {
        DetailViewController *detailView = [segue destinationViewController];

        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];

        theList = [app.listArray objectAtIndex:indexPath.row];

        detailView.theList = theList;

        detailView.streamQuality = quality;

    }
}

DetailViewController.h

@property (nonatomic ,retain) NSString *streamQuality;

DetailViewController.m

@synthesize streamQuality;

NSLog(@"Final: %@", streamQuality);

输出:大多数我得到“线程1:EXC_BAD_ACCESS(代码= 2,地址= 0x10)”
或类似随机的东西 “最终:复制音频地址”


然而,这样可行:

detailView.streamQuality = @"hello";

1 个答案:

答案 0 :(得分:1)

您应该创建一个属性以保留NSString对象质量。 对于Eg:

@property (nonatomic ,copy) NSString *quality;

当然你必须综合它:

@synthesize quality;

然后你应该使用这个属性来设置字符串。像这样:

self.quality = @"string to pass";