我有一點問題,因爲我無法將數據傳遞給另一個視圖控制器。無法將數據傳遞給其他viewController ios
-(void)barcodeData:(NSString *)barcode type:(int)type
{
mainTabBarController.selectedViewController=self;
[status setString:@""];
[status appendFormat:@"Type: %d\n",type];
[status appendFormat:@"Type text: %@\n",[dtdev barcodeType2Text:type]];
[status appendFormat:@"Barcode: %@",barcode];
[displayText setText:status];
codede1String = barcode;
NSLog(@"%@",codede1String);
[self updateBattery];
}
在上面我的代碼把條形碼在String codeString1
。到目前爲止沒有問題,但是當我將這個數據發送給另一個viewController時,barCodeString突然變爲NULL。
我將數據傳遞給視圖控制器是這樣的:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:@"barcode"]) {
main =[ segue destinationViewController];
main.code1.text = codede1String;
}
}
那麼,如何解決這個問題?
試着在調試器的幫助下理解你的代碼。 – dasdom 2013-03-20 15:26:31