0

本のいくつかの章を読んだ後、いくつかのトピックを再現してみることにしました。あくまでも練習目的です。

実行しようとすると、Xcode でエラーが表示されます

 Thread1: signal SIGABRT
and the console shows: 2012-07-16 11:19:46.401 MyProject[595:11303] (null)
libc++abi.dylib: terminate called throwing an exception
(lldb) 

テーブル付きのビューを表示しようとしています。appDelegate のコードは次のとおりです。

#import "MyProjectAppDelegate.h"
#import "MyProjectViewController.h"

@implementation MyProjectAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    MyProjectViewController *myProjectViewController = [[MyProjectViewController alloc] init];

    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:myProjectViewController];

    [[self window] setBackgroundColor:[UIColor whiteColor]];
    [[self window] setRootViewController:navController];
    [[self window] makeKeyAndVisible];

    return YES;
}

そして私の他のviewController:

#import "MyProjectViewController.h"

@interface MyProjectViewController ()

@end

@implementation MyProjectViewController

- (id)init{

    self = [super initWithStyle:UITableViewStyleGrouped];

    if(self){

        UINavigationItem *n = [self navigationItem];
        n.title = @"MyProject";

        UIBarButtonItem *addBarButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addNewItems:)];

        self.navigationItem.rightBarButtonItem = addBarButton;
        self.navigationItem.leftBarButtonItem = self.editButtonItem;
    }

    return self;
}

- (id)initWithStyle:(UITableViewStyle)style
{
    return [self init];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"tableCell"];

    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"tableCell"];
    }

    cell.textLabel.text = @"OI";

    return cell;
}

@end    

シミュレーターをリセットして Mac を再起動しようとしました。前もって感謝します。

4

0 に答える 0