1

私はプログラミングが初めてで、Xcode と Obj-C を使用することから始めることにしました。

2番目のView Controllerにユーザーの場所にズームするはずのマップが含まれているタブ付きアプリケーションを作成しています。コードを正しく取得できないと思います。iOS シミュレーターでアプリを実行しようとすると、2 番目のビュー コントローラーを開くとクラッシュします。

#import <UIKit/UIKit.h>

#import "AppDelegate.h"

int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));



    }
}

@autoreleasepool 内で、実行ごとに「スレッド 1: シグナル SIGABRT」を取得します。

これは、2番目のView Controllerを開いたときに得られる出力です

2013-08-05 21:31:26.271 placerate[56730:c07] Couldn't find default.styleproto in framework
2013-08-05 21:31:26.277 placerate[56730:c07] *** Terminating app due to uncaught exception              'NSUnknownKeyException', reason: '[<UIViewController 0x98a1120> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key mapView.'
*** First throw call stack:
(0x16b3012 0x14d8e7e 0x173bfb1 0xf84e41 0xf065f8 0xf060e7 0xf30b58 0x63a019 0x14ec663    0x16ae45a 0x638b1c 0x4fd7e7 0x4fddc8 0x4fdff8 0x4fe232 0x51f8c9 0x51f704 0x51dbda 0x51da5c    0x51f647 0x14ec705 0x4202c0 0x420258 0x642ff4 0x14ec705 0x4202c0 0x420258 0x4e1021 0x4e157f    0x4e1056 0x646af9 0x14ec705 0x4202c0 0x420258 0x4e1021 0x4e157f 0x4e06e8 0x44fcef 0x44ff02   0x42dd4a 0x41f698 0x2500df9 0x2500ad0 0x1628bf5 0x1628962 0x1659bb6 0x1658f44 0x1658e1b 0x24ff7e3 0x24ff668 0x41cffc 0x22fd 0x2225)
libc++abi.dylib: terminate called throwing an exception
(lldb) 

これは、「自動」ペインの下の出力です。

argc = (int)1
argv = (char **)0xbffff3b4

SecondViewController.h :

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>



@interface SecondViewController : UIViewController 
<MKMapViewDelegate>


@property (strong, nonatomic) IBOutlet MKMapView *mapView;
- (IBAction)zoomIn:(id)sender;
- (IBAction)changeMapType:(id)sender;





@end

SecondViewController.m :

#import "SecondViewController.h"

@interface SecondViewController ()

@end

@implementation SecondViewController

- (IBAction)zoomIn:(id)sender {
    MKUserLocation *userLocation = _mapView.userLocation;
    MKCoordinateRegion region =
    MKCoordinateRegionMakeWithDistance ( userLocation.location.coordinate, 50, 50);
    [_mapView setRegion:region animated:NO];
}

- (IBAction)changeMapType:(id)sender {
if (_mapView.mapType == MKMapTypeStandard)
    _mapView.mapType = MKMapTypeSatellite;
else
    _mapView.mapType = MKMapTypeStandard;
}

- (void)mapView:(MKMapView *)mapView
didUpdateUserLocation:
(MKUserLocation *)userLocation
{
    _mapView.centerCoordinate =
    userLocation.location.coordinate;
}

- (void)viewDidLoad
{
[super viewDidLoad];
_mapView.showsUserLocation = YES;
_mapView.delegate = self; 



}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end

私はこの問題に関するチュートリアルに従いました。お気づきかもしれませんが、これは私にとってかなりギリシャ語です。問題に関する追加情報を提供させていただきます。前もって感謝します、

よろしくお願いします

編集:新しいプロジェクトを作成し、コードの一部をリサイクルしましたが、何らかの理由で機能しました。さまざまな回答と解決策が、プログラミングに取り組むときにもっと注意を払うように促したと思います。これは私の最初のプロジェクトなので、さらに問題が発生する可能性があると思います。時間を割いて質問に答えてくれてありがとう。(私は実際にコードがエキサイティングだと思います)

  • イングベ
4

3 に答える 3

0

ストーリーボードのインスペクター ペインで、2 番目のビュー コントローラーのクラスを SecondViewController に設定するだけでよいようです。まだストック UIViewController に設定されています。

于 2013-08-05T20:08:53.557 に答える
0

styleproto ファイルの欠落が問題のようです。この SO の回答を参照してください: iOS6 Simulator MKMapKit "Couldn't find default.styleproto in framework"

ストーリーボードまたは NIB を使用していますか? その場合は、この SO の回答を確認し、IB で適切なカスタム クラスを設定していることを確認してください: NSInvalidArgumentException isKindOfClass

于 2013-08-05T22:19:38.367 に答える