我正在尝试iphone编程。我一直在关注这个教程,但它似乎并不适合我。 i use this tutorial link
我已多次检查代码并且似乎是正确的,但是当我运行应用程序并推送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)backtrace
#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];
}
有什么想法吗?
答案 0 :(得分:1)
像这段代码一样保留你的数组:
tableData = [NSArray arrayWithObjects:@"one", @"Two", @"Three", @"Four", @"five", nil];
[tableData retain];
我希望这段代码对你有用。
答案 1 :(得分:0)
您的代码非常适合我。
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
这不是必需的协议方法,但通常会使应用程序正常运行。当然,可以省略这种方法。
也许你应该检查一下你的班级是否符合UITableViewDataSource
和UITableViewDelegate
。然后检查IB中的tableview是否已设置其数据源并委托给文件所有者。
编辑:
您可以从断点导航器添加异常断点,以查找引发异常的确切位置。请提供一些更详细的错误日志。