Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.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
Ios tableView在向其添加对象后崩溃_Ios_Objective C_Uitableview_Segue_Ibaction - Fatal编程技术网

Ios tableView在向其添加对象后崩溃

Ios tableView在向其添加对象后崩溃,ios,objective-c,uitableview,segue,ibaction,Ios,Objective C,Uitableview,Segue,Ibaction,当某人在文本字段中输入某个内容,然后按下“完成”按钮时,它应该将该值添加到我的NSMutableArray中。以下是此操作的代码: - (IBAction)Fertig: (UIStoryboardSegue *)segue2; { KategorieTableViewNeueKategorieViewController *KategorieTVNeueKategorieVC = segue2.sourceViewController; KategorienTableViewControlle

当某人在文本字段中输入某个内容,然后按下“完成”按钮时,它应该将该值添加到我的NSMutableArray中。以下是此操作的代码:

- (IBAction)Fertig: (UIStoryboardSegue *)segue2;
{
KategorieTableViewNeueKategorieViewController *KategorieTVNeueKategorieVC = segue2.sourceViewController;
KategorienTableViewController *neuerKategoriename = [[KategorienTableViewController alloc]initwithData: KategorieTVNeueKategorieVC.neuerKategoriename];
[self.Kategorie addObject: neuerKategoriename];

[self.tableView reloadData];


}
我也实现了initwithData方法,但我不知道这是否正确:

-(id)initwithData:(NSMutableString *)theName
{
if (self)
{
    self.Kategorie = [theName mutableCopy]  ;
}
return self;
}
我可以将该值添加到我的表视图中,但如果我向下滚动到该值的底部,我的应用程序将崩溃,并收到错误警告“Thread 1:signal SIGABRT”

以下是我的CellForRowatineXpath方法的代码:

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

if (!cell)
{
    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}

if (tableView == self.tableView)
{
    cell.textLabel.text = self.kategorie [indexPath.row];
}
else
{
    cell.textLabel.text = self.results [indexPath.row];
}

// Configure the cell...

    return cell;

}

我做错了什么?如果这个问题太简单,我很抱歉,但我是新来的开发人员。如果您需要更多信息,请咨询

您的代码非常混乱

segue2 iAction将“Kategorie”属性视为可变数组

(顺便说一句,类名应该以大写字母开头,属性名/ivar/方法名应该以小写字母开头。这在iOS和Mac OS中是一种非常强大的命名约定,实际上是属性setter/getter方法正常工作所必需的。)

然后你发布了一些东西的初始代码,但你没有说什么。告诉我们该代码属于哪个类,并发布该类的整个标题

但是,您的init方法无法调用
[super init]
,这是一个错误

Init方法应如下所示:

-(id)initwithData:(NSMutableString *)theName
{
  self = [super init]; //You were missing this step.
  if (self)
  {
    self.Kategorie = [theName mutableCopy]  ;
  }
  return self;
}

我不能真正理解你的代码。是否使用名为Kategorie的变量创建viewController的实例,然后将其添加到数据源数组中?您还可以显示您的
cellforrowatinexpath
code吗?
Kategorie
应该是一个
NSMutableArray
?在
initWithData:
方法中将其初始化为
NSMutableString
。它应该是
[self.Kategorie addObject:theName.mutableCopy]
当我执行此操作时,我收到错误警告,无法将其分配给init族中的方法之外的“self”