【发布时间】:2012-03-27 21:05:41
【问题描述】:
我有一个由 nib 构建的 MainWindow 类,设置如下:
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
MainViewController *mainView = [[MainViewController alloc] initWithNibName:@"MainViewController"
bundle:nil];
if(!mainView)
{
return;
}
naviController = [[UINavigationController alloc] initWithRootViewController:mainView];
[naviController setToolbarHidden:YES];
[[naviController navigationBar] setTintColor:[UIColor blackColor]];
[[naviController toolbar] setTintColor:[UIColor blackColor]];
[self.window setRootViewController:naviController];
[self.window makeKeyAndVisible];
}
这可以正常工作并正确显示MainViewController,但是当我尝试在MainViewController 的表格视图中向下滚动时,它会抛出EXC_BAD_ACCESS。显然 UIKit 指的是第二个 MainViewController,它是在 [self.window makeKeyAndVisible]; 中构建的
这是两个MainViewControllers。第一个我初始化,第二个在makeKeyAndVisible创建。
这是第二个被称为僵尸的MainViewController。
关于为什么会发生这种情况的任何想法?
根据要求:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
MainViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MainViewCell"];
int i = [indexPath row];
NSLog(@"%d\n",i);
if (cell == nil) {
// Create a temporary UIViewController to instantiate the custom cell.
UIViewController *temporaryController = [[UIViewController alloc] initWithNibName:@"MainViewCell" bundle:nil];
// Grab a pointer to the custom cell.
cell = (MainViewCell *)temporaryController.view;
// Release the temporary UIViewController.
[temporaryController release];
}
[[cell icon] setImage:[UIImage imageNamed:[[moduleXMLList objectAtIndex:i] objectForKey:@"thumbnail"]]];
[[cell title] setText:[[moduleXMLList objectAtIndex:i] objectForKey:@"title"]];
[[cell description] setText:[[moduleXMLList objectAtIndex:i] objectForKey:@"description"]];
return cell;
}
【问题讨论】:
-
你试过清理所有目标吗?
-
现在我有了。结果是一样的。
-
除此之外,解决此类问题的方法通常是重置模拟器中的内容和设置,重启 Xcode,必要时重启计算机
-
哇,这看起来很奇怪。它可能类似于这个问题 - stackoverflow.com/questions/3739405/… 吗?烦人地没有合适的解决方案,但也许有帮助?
-
还是没有运气。可能还值得一提的是,我正在加载自定义
UITableViewCells,如 bdunagan.com/2009/06/28/… 所述,虽然最初加载很少,但当我尝试向下滚动到新单元格时会引发异常。话虽如此,它不是从我的任何方法中抛出的。
标签: objective-c ios ios5 uikit