我需要使用视图控制器类中的SecondViewController的按钮来删除数组。从C-Objective中的另一个类中删除一个NSMutableArray?
目前,我有这样的:
- (IBAction)deleteArrayFromSeconViewController:(id)sender // is the Button which should
// delete the array
{
self.textLabel2.text = @""; // this work fine
ViewController *vc = [[ViewController alloc]init];
[vc.textViewArray removeAllObjects]; // do not remove the objects?
}
我应该怎么做超车从SecondViewControllerClass在ViewControllerClass订单?
我也试过这个在SecondViewControllerClass:
- (IBAction)deleteArrayFromSeconViewController:(id)sender
{
self.textLabel2.text = @"";
ViewController *vc = [[ViewController alloc]init];
[vc deleteTheArray];
}
来调用ViewControllerClass此功能:
- (void) deleteTheArray
{
[textViewArray removeAllObjects];
}
你可能需要一个指向当前存在的“另一个视图控制器”,而不是创造新的。 – Krizz 2012-01-03 17:46:16
在您调用的另一个ViewController上创建一个方法来清除该数组也可能是值得的,以便它可以选择运行任何内务代码,而不是将数据从其下拉出来。即使现在没有必要的内务管理,它也会使未来的重构更容易:) – matthias 2012-01-03 17:49:46