【发布时间】:2013-09-17 10:43:54
【问题描述】:
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(code=2, address=0x10)”
或类似的随机
《决赛:复制音频地址》
但是这很好用:
detailView.streamQuality = @"hello";
【问题讨论】:
-
什么是质量?在将它传递给 detailViewController 之前,你检查过它的值吗?
-
您在使用 ARC 吗?如果不是,则 stringWithFormat 返回自动释放的字符串,因此您需要保留它。尝试使用: quality = [[NSString stringWithFormat:@"string to pass"] retain];.
标签: ios objective-c cocoa-touch nsstring