1

我正在尝试 iPhone 编程。我一直在关注本教程,但它似乎对我不起作用。 我使用这个教程链接

我已经检查了几次代码,似乎是正确的,但是当我运行应用程序并推送tableview应用程序时crashes。没有错误或warnings. 任何帮助,将不胜感激。这是代码。

@implementation SimpleTableViewController
{
NSArray *tableData;
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Initialize table data
tableData = [NSArray arrayWithObjects:@"one", @"Two", @"Three", @"Four", @"five",      nil];
} 


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


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleTableItem";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

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

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

我正在接收EXC_BAD_ACCESS

这是回溯(gdb)回溯

#0  0x00efe5a8 in objc_exception_throw ()
#1  0x00d62628 in +[NSException raise:format:arguments:] ()
#2  0x00d6259a in +[NSException raise:format:] ()
#3  0x00362b75 in -[UIViewController _loadViewFromNibNamed:bundle:] ()
#4  0x00360709 in -[UIViewController loadView] ()
#5  0x003605e3 in -[UIViewController view] ()
#6  0x0035ea57 in -[UIViewController contentScrollView] ()
#7  0x0036f201 in -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:] ()
#8  0x0036d831 in -[UINavigationController _layoutViewController:] ()
#9  0x0036eb4c in -[UINavigationController _startTransition:fromViewController:toViewController:] ()
#10 0x00369606 in -[UINavigationController _startDeferredTransitionIfNeeded] ()
#11 0x0037083e in -[UINavigationController pushViewController:transition:forceImmediate:] ()
#12 0x003694a0 in -[UINavigationController pushViewController:animated:] ()
#13 0x000022cf in -[PocketHusbandViewController displayCarView:] (self=0x4e12870, _cmd=0x31d2, sender=0x4e16f30) at /Users/wayne/Desktop/programming/Pocket Husband/Classes/PocketHusbandViewController.m:21
#14 0x002b2a6e in -[UIApplication sendAction:to:from:forEvent:] ()
#15 0x003411b5 in -[UIControl sendAction:to:forEvent:] ()
#16 0x00343647 in -[UIControl(Internal) _sendActionsForEvents:withEvent:] ()
#17 0x003421f4 in -[UIControl touchesEnded:withEvent:] ()
#18 0x002d70d1 in -[UIWindow _sendTouchesForEvent:] ()
#19 0x002b837a in -[UIApplication sendEvent:] ()
#20 0x002bd732 in _UIApplicationHandleEvent ()
#21 0x016dfa36 in PurpleEventCallback ()
#22 0x00d8b064 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ ()
#23 0x00ceb6f7 in __CFRunLoopDoSource1 ()
#24 0x00ce8983 in __CFRunLoopRun ()
#25 0x00ce8240 in CFRunLoopRunSpecific ()
#26 0x00ce8161 in CFRunLoopRunInMode ()
#27 0x016de268 in GSEventRunModal ()
#28 0x016de32d in GSEventRun ()
#29 0x002c142e in UIApplicationMain ()
#30 0x00001e90 in main (argc=1, argv=0xbfffefd4) at /Users/wayne/Desktop/programming/

我认为当我调用视图时问题可能就在这里;

-(IBAction)displayView:(id)sender {
carMainViewController *carViewController = [[carMainViewController alloc]initWithNibName:@"carMainViewController" bundle:[NSBundle mainBundle]];
[carViewController.navigationItem setTitle:@"Cars"];
[self.navigationController pushViewController:carViewController animated:YES];
[carViewController release];

}

有什么想法吗?

4

2 回答 2

1

像以下代码一样保留您的数组:

 tableData = [NSArray arrayWithObjects:@"one", @"Two", @"Three", @"Four", @"five",      nil];
[tableData retain];

我希望这段代码对你有用。

于 2013-09-10T05:25:05.620 回答
0

您的代码非常适合我。

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 

这不是必需的协议方法,但通常可以使应用程序正常运行。当然,可以省略此方法。

也许你应该检查你的班级是否符合UITableViewDataSourceand UITableViewDelegate。然后检查您在 IB 中的 tableview 是否已设置其数据源并委托给文件所有者。

在此处输入图像描述

编辑:

您可以从断点导航器添加异常断点,以找到引发异常的确切位置。并请提供一些更详细的错误日志。

在此处输入图像描述

于 2013-09-10T02:20:34.237 回答