1

ビューの下部にあるタブバーボタンをクリックすると、セグエを介して dataViewController と呼ばれる別のビューコントローラーを MainViewController の中央のメインビューに取り込む MainViewController があります。dataViewController には、配列から生成される UITableView があります。dataViewcontroller に最初のシーン ビュー コントローラーを指定すると、正常に動作し、テーブルとそのすべてのセル/コンテンツをロールスルーできるため、単純なものが不足していると思います。MainViewController を最初のシーン ビュー コントローラーにするとすぐに、[データ] ボタンをクリックすると、ビューが変更され、テーブルビューが読み込まれます。個々のセルを選択して強調表示できますが、テーブルをロールスルーしようとすると、シミュレーターがクラッシュし、理由のように見えますか?

MainViewController.h

#import <UIKit/UIKit.h>

@interface MainViewController : UIViewController

@property (weak,nonatomic)UIViewController *currentViewController;
@property (weak, nonatomic) IBOutlet UIView *mainView;

@end

MainViewController.m

#import "MainViewController.h"

@interface MainViewController ()

@end

@implementation MainViewController

@synthesize currentViewController;
@synthesize mainView;

- (void)viewDidLoad {
    [super viewDidLoad];
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    if ([defaults objectForKey:@"location"] == NULL) [defaults setObject:@"Spring Hill" forKey:@"location"];
    if ([defaults objectForKey:@"temperature"] == NULL) [defaults setObject:@"Celsius" forKey:@"temperature"];
    if ([defaults objectForKey:@"windSpeed"] == NULL)   [defaults setObject:@"kph" forKey:@"windSpeed"];
    if ([defaults objectForKey:@"wingType"] == NULL)    [defaults setObject:@"Paraglider" forKey:@"wingType"];
    [defaults synchronize];
}

- (void) viewWillAppear:(BOOL)animated {
    [self performSegueWithIdentifier:@"graphSegue" sender:self];
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    self.navigationItem.title = [defaults objectForKey:@"location"];
}

@end

CustomTabBarSegue.h

#import <UIKit/UIKit.h>

@interface CustomTabBarSegue : UIStoryboardSegue

@end

CustomTabBarSeque.m

#import "CustomTabBarSegue.h"
#import "MainViewController.h"

@implementation CustomTabBarSegue

- (void) perform {
    MainViewController *currentView = (MainViewController *)self.sourceViewController;
    UIViewController *destView = (UIViewController *) self.destinationViewController;
    for(UIView *view in currentView.mainView.subviews){
        [view removeFromSuperview];
    }
    currentView.currentViewController = destView;
    [currentView.mainView addSubview:destView.view];
}

@end

それがストーリーボードにあるもので、チェック/選択していないものなのか、それとも不適切なコードなのかわかりませんか? ありがとう。

4

1 に答える 1

0

.header ファイルでは、このビューが次のように UITableView プロトコルに準拠することを指定する必要があります。

@interface MainViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>

コードで UITableView が宣言されていないようですが。ストーリーボードに配置して、次のように viewDidLoad メソッドでデリゲートとデータソースを設定するだけでなく、プロパティとして宣言する必要があります。

self.myTableView.delegate = self;
self.myTableView.datasource = self;
于 2013-10-28T06:12:54.757 に答える