Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.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
Objective c 使用self.tableview重新加载数据崩溃应用程序_Objective C_Uitableview_Crash - Fatal编程技术网

Objective c 使用self.tableview重新加载数据崩溃应用程序

Objective c 使用self.tableview重新加载数据崩溃应用程序,objective-c,uitableview,crash,Objective C,Uitableview,Crash,我正在用XCode做一个简单的应用程序,有两个TableViewController,点击第一个会把你带到第二个你的名字,但是我遇到了一个崩溃,那行写着:“self.tableView reloadData”,我如何解决这个问题? 我到了主干道,说线程1:信号SIGABRT argv字符**0xbfffed90 0xbfffed90 *argv char*“/Users/maciosdevelopment/Library/Application Support/iPhone Simulator/

我正在用XCode做一个简单的应用程序,有两个TableViewController,点击第一个会把你带到第二个你的名字,但是我遇到了一个崩溃,那行写着:“self.tableView reloadData”,我如何解决这个问题? 我到了主干道,说线程1:信号SIGABRT argv字符**0xbfffed90 0xbfffed90 *argv char*“/Users/maciosdevelopment/Library/Application Support/iPhone Simulator/7.0.3/Applications/20050884-B77A-47FC-98B6-500B5D44D9FB/eEmplomodal.app/eEmplomodal”0xbfffef10 **argv字符'/''/' argc int 1

NSMutableArray *alumnos;

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:@"transicion"]){
    UINavigationController *navigationController=segue.destinationViewController;
    MODetalleViewController *moDetalleViewController =[[navigationController viewControllers]objectAtIndex:0];
    moDetalleViewController.delegate=self;
}
}

- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
    // Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];
alumnos=[NSMutableArray array];
}

-(void)viewDidUnload{
[self viewDidUnload];
alumnos=nil;
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Alumno";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

// Configure the cell...

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

#pragma mark Protocolo de detalle

-(void)AlumnoDetallesViewControllerDelegateDidCancel:(MODetalleViewController *)controller{
[self dismissViewControllerAnimated:YES completion:nil];
}

-(void)AlumnoDetallesViewControllerDelegateDidSave:(MODetalleViewController *)controller{
[self dismissViewControllerAnimated:YES completion:nil];
[alumnos addObject:controller.nombre.text];
[self.tableView reloadData];
}
这将进入一个无限循环。更正
[super viewDidUnload]

将解雇代码放在方法的末尾,然后重试

-(void)AlumnoDetallesViewControllerDelegateDidSave:(MODetalleViewController *)controller{

[alumnos addObject:controller.nombre.text];
[self.tableView reloadData];
[self dismissViewControllerAnimated:YES completion:nil];
}

我认为问题可能是由于访问您同时解雇的控制器的成员造成的:

-(void)AlumnoDetallesViewControllerDelegateDidSave:(MODetalleViewController *)controller{
   [self dismissViewControllerAnimated:YES completion:nil];
   [alumnos addObject:controller.nombre.text];
   [self.tableView reloadData];
}
尝试:

[alumnos addObject:[controller.nombre.text copy]];
这将向数据源添加在“详细信息控制器”视图中输入的文本副本

更好的建议是将数据源作为应用程序模型的一部分(如在模型视图控件中)。因此,当用户输入新的详细信息时,您的详细视图控制器将更新应用程序模型;主视图控制器可以从模型而不是从详图控制器访问新数据


(如果您不使用ARC,这将产生内存泄漏,顺便说一句,您应该添加
自动释放

您可以发布崩溃日志吗。我感觉“
self.tableView
”没有正确连接。是的,我有错。然而,这并不能解决问题。感谢您的帮助。您可以发布崩溃日志吗?您正在关闭viewController并访问它的属性!当您关闭ViewController时,它将调用viewDidUnload:并且您无法访问局部变量。因此,在最后关闭viewController!这有用吗?
[alumnos addObject:[controller.nombre.text copy]];