基本的に、次の 2 つのものが必要です。
- ユーザーから文字列を取得する
既にご存じのとおり、テキストフィールドに IBOutlet を設定して文字列を読み取るだけです。
- 別のView Controllerに渡す
これを行うには、次の 2 つのオプションがあります。
まず、2 番目のビュー コントローラーに文字列を追加し、プロパティを設定します。次に、URL 文字列を受け取るカスタム -init を作成します。最初のView Controllerで、2番目のView Controllerを作成するときに(その場合だと思います)、カスタム -init を使用して値を設定します。
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil andURL:(NSString *) url
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
self.urlString = url;
}
return self;
}
別のオプションがあります。2 番目のビュー コントローラーでメソッドを作成します。
したがって、2 番目のビュー コントローラーで次のようにします。
-(void) setURL: (NSString *) url
{
self.rulString = url;
}
最初のView Controllerで、次のようにします。
SecondViewController *secondVC = [SecondViewController alloc] init];
// get url string from user input and store it in a local string variable named tempURL
[secondVC setURL:tempURL];
お役に立てれば。