-1

我不确定这表明了什么,但任何帮助都会很棒。

这是来自 mainviewcontroller 的代码

#import "MainViewController.h"

#import "ECSlidingViewController.h"
#import "MenuViewController.h"

@interface MainViewController ()

@end

@implementation MainViewController
{
    NSArray *toDoList;
}

@synthesize menuBtn;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    // Do any additional setup after loading the view.
    [super viewDidLoad];
    //initialize table data
    toDoList = [NSArray arrayWithObjects:@"Apples", "Bananas", "Soda", nil];

...

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [toDoList count];

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *simpleTableIdentifier = @"ToDoList";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
    }

    cell.textLabel.text = [toDoList objectAtIndex:indexPath.row];
    return cell;

}

从滑动视图控制器

- (void)setTopViewController:(UIViewController *)theTopViewController
{
  CGRect topViewFrame = _topViewController ? _topViewController.view.frame : self.view.bounds;

  [self removeTopViewSnapshot];
  [_topViewController.view removeFromSuperview];
  [_topViewController willMoveToParentViewController:nil];
  [_topViewController removeFromParentViewController];

  _topViewController = theTopViewController;

  [self addChildViewController:self.topViewController];
  [self.topViewController didMoveToParentViewController:self];

  [_topViewController.view setAutoresizingMask:self.autoResizeToFillScreen];
  [_topViewController.view setFrame:topViewFrame];
  _topViewController.view.layer.shadowOffset = CGSizeZero;
  _topViewController.view.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.view.layer.bounds].CGPath;

  [self.view addSubview:_topViewController.view];
}

初始化视图控制器..

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.topViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"Main"];
  }

和 main.m

#import "AppDelegate.h"

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

1 回答 1

4

崩溃是由以下代码行引起的viewDidLoad

toDoList = [NSArray arrayWithObjects:@"Apples", "Bananas", "Soda", nil];

您正在尝试添加一个NSString和两个 C 字符串。试试这个:

toDoList = [NSArray arrayWithObjects:@"Apples", @"Bananas", @"Soda", nil];

我很惊讶这行代码没有编译器警告。永远不要忽略编译器警告。

于 2013-01-29T01:39:44.230 回答