2

geoPoint オブジェクトを受け取るブロック内に次のコードがあります。

UIViewController *mapViewController1 =
                [[BSTGMapViewController alloc] initWithNibName:@"BSTGMapViewController_iPhone"
                                                           bundle:nil];
PFGeoPoint *currentLocation = geoPoint;
[self presentViewController:mapViewController1 animated:1 completion:nil];

geoPoint 変数を mapViewController1 に渡して、

viewDidLoad 関数? XCode 4.6 を使用して iOS 5 をターゲットにしています。どうすればこれを解決できますか?

4

5 に答える 5

3

BSTGMapViewController オーバーロード initWithNibName 内でパラメーターを渡す

BSTGMapViewController 内。

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil withGeoPoint:(CLLocation*)userLocation;

BSTGMapViewController.mに実装します

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil withGeoPoint:(CLLocation*)userLocation
{
//usual code of init with nib name
locationhere=userlocation;

}

//あなたのコード

PFGeoPoint *currentLocation = geoPoint;
BSTGMapViewController *mapViewController1 =
                [[BSTGMapViewController alloc] initWithNibName:@"BSTGMapViewController_iPhone"
                                                           bundle:nil withGeoPoint:currentLocation];

[self presentViewController:mapViewController1 animated:1 completion:nil];
于 2013-03-21T11:29:49.680 に答える
1

次のコードのように init メソッドをオーバーライドし、新しいビュー コントローラーに値を送信できます

新しいビュー インターフェイスでの宣言

- (id)initWithTeamCount:(int)teamCount

新しいビュー インターフェイスでの定義

- (id)initWithTeamCount:(int)teamCount {
    self = [super initWithNibName:nil bundle:nil];
    if (self) {
        // Custom initialization
        self.teamCountLabel.text = [NSString stringWithFormat:@"%d",teamCount];
    }
    return self;
}

最初のビューから値を渡す

SetTeamsViewController *vc = [[SetTeamsViewController alloc] initWithTeamCount:self.teamCount];
于 2013-03-21T11:28:44.287 に答える
0

表示されるviewControllerでプロパティを定義します。プロパティのタイプは、渡すタイプになります。

プロパティを定義した後、それを提示するクラスで作成したオブジェクトを使用してアクセスできます。

BSTGMapViewController *mapViewController1 =
                [[BSTGMapViewController alloc] initWithNibName:@"BSTGMapViewController_iPhone"
                                                           bundle:nil];
mapViewController1.propertyName = valueToBePassed;

[self presentViewController:mapViewController1 animated:1 completion:nil];

それでおしまい。viewDidLoad でアクセスできます。

于 2013-03-21T11:25:02.857 に答える
0

初期化方法を次のように変更します-(id)initWithNubName:(NSString*)nibName bundle:(NSBundle*)nibBundle;-(id)initWithNubName:(NSString*)nibName bundle:(NSBundle*)nibBundle location:(PFGeoPoint*)geoLocation;

currentLocationタイプPFGeoPoint*inのプロパティを定義しますBSTGMapViewController。初期化メソッドで、プロパティをパラメーターにある値に設定します。

オブジェクトviewDidLoadのプロパティ値を使用します。PFGeoPoint*

于 2013-03-21T11:28:47.800 に答える
0

BSTGMapViewController のカスタム初期化子を以下のように記述します

-(id)initWithGeoPoint:(PFGeoPoint *)point
{
   self = [super initWithNibName:@"BSTGMapViewController_iPhone"
                                                           bundle:nil];
   if(self)
   {
       //here geopoint is class member
       geopoint = point;
   }
}

そして使う

PFGeoPoint *currentLocation = geoPoint;
UIViewController *mapViewController1 =
                [[BSTGMapViewController alloc] initWithGeoPoint:currentLocation];

お役に立てれば。

于 2013-03-21T11:27:32.613 に答える