Adr*_*ian 1 objective-c uilabel ios segue
我有一个prepareForSegue在该方法设置发送我想要的一切的destinationViewController除了一个值UILabel上destinationVC.我扔了一个NSLog语句来查看它打印的值,它打印出我想要的内容.
它不会崩溃,但它没有设置.我知道我在这里遗漏了一些非常基本的东西,但它并没有向我跳出来.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(UIButton *)sender {
if ([[segue identifier] isEqualToString:@"directionsSegue"]) {
// Set destination view controller
DirectionsViewController *destinationVC = segue.destinationViewController;
// Pick out the "thing" you want to send to destinationVC
CGPoint point = [sender convertPoint:CGPointZero toView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:point];
// Set the "thing" on the destinationVC
PointOfInterest *poi = [self.fetchedResultsController objectAtIndexPath:indexPath];
destinationVC.destinationLabel.text = poi.name;
NSLog(@"destinationVC.destinationLabel.text = %@", poi.name);
destinationVC.destinationLatitude = poi.latitude;
destinationVC.destinationLongitude = poi.longitude;
}
}
Run Code Online (Sandbox Code Playgroud)
我的属性在destinationVC的标题中声明:
@property (strong, nonatomic) IBOutlet UILabel *destinationLabel;
Run Code Online (Sandbox Code Playgroud)
以下答案的解决方案:
谜团已揭开!这是我做的:
在我的目标VC上,我将其添加到我的标题中:
@property (nonatomic, strong) NSString *destinationName;
Run Code Online (Sandbox Code Playgroud)
我把它放回实施中:
@property (strong, nonatomic) IBOutlet UILabel *destinationLabel;
Run Code Online (Sandbox Code Playgroud)
在destinationVC,我把这个添加到我的viewDidLoad:
self.destinationLabel.text = self.destinationName;
Run Code Online (Sandbox Code Playgroud)
您的标签将为零,prepareForSegue因为此时它不会实例化.实际上,一旦加载了视图,IBOutlet就会被初始化.这就是为什么它不起作用.
解决问题的最佳方法是在您DirectionsViewController的文本存储位置创建另一个属性.您可以在控制器初始化后直接使用此标签,然后您可以直接在控制器中的任何位置设置标签.
| 归档时间: |
|
| 查看次数: |
169 次 |
| 最近记录: |