1

我有一个 MainViewController,当单击视图底部的选项卡栏按钮时,它会通过 segue 使用另一个名为 dataViewController 的视图控制器填充 MainViewController 中的中央主视图。在 dataViewController 中,它有一个从数组填充的 UITableView。我想念一些简单的东西,因为当我给 dataViewcontroller 初始场景视图控制器时,它运行良好,我可以滚动表格及其所有单元格/内容。一旦我将 MainViewController 设为初始场景视图控制器,我单击数据按钮,它会更改视图填充 tableview。我可以选择单个单元格并突出显示,但是当我尝试滚动表格时,它会使模拟器崩溃并且确实给出了看起来像一个原因?

主视图控制器.h

#import <UIKit/UIKit.h>

@interface MainViewController : UIViewController

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

@end

主视图控制器.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 回答