0

我有一张桌子,我想在其中点击单元格,它会将我带到另一张桌子。在 Xcode 4.3.2 中运行时出现此错误:

 return UIApplicationMain(argc, argv, nil, NSStringFromClass([RanchForecastTouchAppDelegate class]));

 Thread 1: Signal SIGABRT

我在这个论坛上看到很多与此错误相关的答案,但它没有用,这就是我再次提问的原因。

我的代码是: CreateViewController.h

#import <UIKit/UIKit.h>

@interface CreateViewController : UIViewController <
UITableViewDataSource, UITableViewDelegate>
{
NSArray *tableData;

}

@property (nonatomic, retain) NSArray *tableData;
@end

创建视图控制器.m

#import "CreateViewController.h"

@implementation CreateViewController
@synthesize tableData;


#pragma mark - View lifecycle

- (void)viewDidLoad
{
tableData = [[NSArray alloc] initWithObjects:@"Johan", @"Paul",@"George",@"Ringo", nil];
[super viewDidLoad];
// Do any additional setup after loading the view.
}

#pragma mark - TableView Data Source methods

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

}


  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
UITableViewCell *cell = nil;

cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell"];
if(cell == nil)
{
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyCell"];

}
cell.textLabel.text = [tableData objectAtIndex:indexPath.row];

return cell;
}


 @end

控制台上的错误消息:

[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x68ab4d0

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x68ab4d0'

编辑:

#import "RanchForecastTouchViewController.h"

@interface RanchForecastTouchViewController ()

@end

@implementation RanchForecastTouchViewController

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
    return YES;
}
}

 @end

RanchForecastTouchViewController.h

#import <UIKit/UIKit.h>

@interface RanchForecastTouchViewController : UIViewController

@end
4

2 回答 2

0

您在行尾添加了分号

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

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

只需删除它们

于 2012-04-23T10:32:35.847 回答
0

检查您的用户界面连接,这将是一些错误的连接!

于 2012-04-25T00:26:36.360 回答