我有兩個視圖控制器'FirstViewController'和'SecondViewController'。從第一個視圖控制器中,它將從文本字段獲取輸入,對其進行處理並在第二個視圖中相應顯示。但是,我直接設置標籤值時遇到問題。IOS Segue無法直接設置標籤
@interface SecondViewController : UIViewController
{
NSString *numPlate;
IBOutlet UILabel *output;
};
@property(strong,nonatomic) NSString *numPlate;
@property(strong,nonatomic) IBOutlet UILabel *output;
@end
爲FirstViewController.m的主要文件,爲準備賽格瑞是
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([[segue identifier] isEqualToString:@"Change"])
{
SecondViewController *svc = (SecondViewController *)[segue destinationViewController];
svc.numPlate = input.text;
NumberPlate *numPlate=[[NumberPlate alloc]init];
[numPlate setPlate:input.text];
NSInteger flag=[numPlate checkValidity];
if(flag==0)
{
svc.output.text [email protected]"Invalid License";
}
else
if([numPlate getArea]==NULL||[numPlate getRegOffice]==NULL)
{
svc.output.text [email protected]"Data not found";
}
else
{
svc.output.text [email protected]"VALID License";
}
}
}
但是,當被執行操作的不working.The標籤不改變。 當我用svc.numPlate代替svc.output.text並在SecondViewController viewDidLoad方法和我用
- (void)viewDidLoad
{
[super viewDidLoad];
output.text=numPlate;
}
一切都很好與此有關。第一種方法有什麼不妥?
謝謝,有沒有比傳遞數據到字符串更好的方法。 – slaveCoder
@BittuAby在某種意義上說,這是解決方案,而不是通過全局或靜態來傳遞價值。 –
我是ios編程新手。你可以給我一些關於這些主題的教程鏈接。即全局/靜態 – slaveCoder