Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 尝试由其他类加载时TableView崩溃_Iphone_Ios_Uitableview_Memory_Uiviewcontroller - Fatal编程技术网

Iphone 尝试由其他类加载时TableView崩溃

Iphone 尝试由其他类加载时TableView崩溃,iphone,ios,uitableview,memory,uiviewcontroller,Iphone,Ios,Uitableview,Memory,Uiviewcontroller,我有一个应用程序(联系人风格),你可以将实例添加到表视图中,它可以很好地将对象添加到列表中。该列表将它们完美地呈现在详细视图中。我可以在MasterViewController(导航控制器的UITableViewController和RootController)中调用“添加项”(一个包含TableView的UIViewController)视图任意次数 当我看到这样做有效,并希望扩展我的应用程序的功能以允许用户编辑列表中的当前对象时,我在detailView的Nav控制器中添加了一个“编辑”按

我有一个应用程序(联系人风格),你可以将实例添加到表视图中,它可以很好地将对象添加到列表中。该列表将它们完美地呈现在详细视图中。我可以在MasterViewController(导航控制器的UITableViewController和RootController)中调用“添加项”(一个包含TableView的UIViewController)视图任意次数

当我看到这样做有效,并希望扩展我的应用程序的功能以允许用户编辑列表中的当前对象时,我在detailView的Nav控制器中添加了一个“编辑”按钮,此UiBarButton触发一个方法,尝试加载用于在表视图中添加项的相同“添加项”视图。这就是奇怪的事情开始发生的地方

如果我运行应用程序并点击列表视图中的现有对象,我将成功进入详细视图。如果我点击“编辑”按钮,“添加项目”视图将很好地加载当前正在编辑的对象的数据。然后,我可以多次取消/保存/取消“添加项目”视图,只要我一直从详细信息视图调用它。如果我返回列表视图并尝试添加项目,应用程序将崩溃

如果我启动应用程序,在其他任何操作之前,我从主列表视图加载“添加项”,该视图将完美加载,并且我可以完美地添加任意次数的对象。如果我随后转到“详细信息”视图并尝试编辑对象,应用程序将崩溃

简单放置(如果你懒得阅读上面的内容):每当我尝试从不同的控制器加载“添加项”视图时,应用程序就会崩溃,而不是第一次加载它的控制器

以下是崩溃日志:

    *** Assertion failure in -[UITableView _createPreparedCellForGlobalRow:withIndexPath:], 
    /SourceCache/UIKit_Sim/UIKit-1914.84/UITableView.m:6061
     2012-03-26 21:22:49.087 Vex Try 5[2749:f803] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason:
    'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
    *** First throw call stack: ...
显然,第二次尝试加载时,
cellforrowatinexpath
返回一个奇怪的单元格

以下是我在列表视图中如何称呼它:

- (void)insertNewObject:(id)sender
    {
        if (!_objects) {
             _objects = [[NSMutableArray alloc] init];
        }

        BIDVexTeam *newTeam = [[BIDVexTeam alloc] init];
        [_objects insertObject:newTeam atIndex:0];

        if (!self.addNew) {
            self.addNew = [[BIDEditViewController alloc] init];
        }

        if (!self.editNavController) {
            self.editNavController = [[UINavigationController alloc] initWithRootViewController:self.addNew];
        }

        addNew.title = @"Add New";
        addNew.team = newTeam;
        addNew.parent = self;

        [self presentModalViewController:self.editNavController animated:YES];

    }
下面是我如何从细节视图中调用它:

    - (IBAction)editTeam:(id)sender {

        if (!self.editView) {
            self.editView = [[BIDEditViewController alloc] initWithNibName:@"BIDEditViewController" bundle:[NSBundle mainBundle]];
        }

        if (!self.editNavController) {
            self.editNavController = [[UINavigationController alloc] initWithRootViewController:self.editView];
        }

        editView.title = [NSString stringWithFormat:@"Edit %@", detailTeam.number];
        self.editView.team = self.detailTeam;

        [self presentModalViewController:editNavController animated:YES];
    }
编辑:这是我的cellForRowAtIndexPath方法。。。我没有把它贴在这里,因为它很长,还有我想要实现的屏幕截图:


这肯定表明有可能崩溃。执行此操作的任何行:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
…如果没有已分配的可重用单元,则可能返回nil。在某些情况下,您进行分配,如本例中:

} else if (indexPath.row == kImageRow) {

    static NSString *ImageCellIdentifier = @"ImageCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ImageCellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ImageCellIdentifier];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
。。但在其他几个国家则不然。关于崩溃的一个很好的假设是,它运行的路径中没有触发任何单元格分配


请搜索所有出列呼叫,添加一个检查为零返回,并分配一个适当的单元格。我认为您的崩溃会得到修复。

我认为问题在于您的默认情况。在某些情况下,您直接使用了
dequeueReusableCellWithIdentifier:
,只有在已经创建了单元以防止重复内存分配时,这种方法才有效。如果不先创建单元格,则无法重用该单元格。因此,我猜想在某些情况下,您的单元格会被重用,而不会首先创建。它太长了,所以我以rtf格式上传了它(这样可以保留Xcode的颜色),哇,这解决了崩溃!谢谢,我从来没想过。。但是,如果我想让单元格加载nib文件,如何初始化单元格?我尝试了以下方法:
cell=[[BIDStandardCell alloc]initWithStyle:UITableViewCellStyleDefault重用标识符:StandardCellIdentifier]在if(cell==nil)条件中,得到了以下结果:也尝试了一个简单的
cell=[[BIDStandardCell alloc]init]
但得到了相同的结果:\n有什么提示吗?看起来你可以从nib成功加载一些单元格(如上面的ImageCell片段),你能重用这种方法吗?