Objective C:打开和关闭子视图
这是我的代码,有两个 IBAction 用于打开和关闭两个不同类中的子视图
- (IBAction) showListClient:(id) sender {
if( list == nil){
list = [[ListClient alloc] initWithNibName:@"ListClient" bundle:nil];
[list setDelegate:self];
[self.view addSubview:list.view];
}
}
,现在第一次关闭
-(IBAction)closeListClient {
[self.view removeFromSuperview];
}
是可以的,但是如果我想使用更多时间我的列表,我必须在 closeListClient 中编写
list = nil;
[list release];
现在我的问题是这个“列表”仅在 ListClient 类中声明,因为
ListClient *list;
当我在 CloseListClient 中写入列表时出现错误...我该怎么办?
This is my code with two IBAction for open and close a subview in two different classes
- (IBAction) showListClient:(id) sender {
if( list == nil){
list = [[ListClient alloc] initWithNibName:@"ListClient" bundle:nil];
[list setDelegate:self];
[self.view addSubview:list.view];
}
}
and for close
-(IBAction)closeListClient {
[self.view removeFromSuperview];
}
now it's ok for the first time, but if I want use more time my list I must write in closeListClient
list = nil;
[list release];
now my problem is this "list" is declared only in the class ListClient as
ListClient *list;
and when I write list in CloseListClient is an error...what can I do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在ListCLient.h中为其委托定义一个协议:
并修改
delegate
的属性定义:然后在调用closeListClient操作时向委托发送消息(在ListClient.m中):
然后最后在SomeController中.m 实现委托方法:
我希望能解决您的问题。
In ListCLient.h define a protocol for its delegate:
and modify the property definition for
delegate
:Then send a message to the delegate when the closeListClient action is called (in ListClient.m):
Then finally in SomeController.m implement the delegate method:
I hope that solves your proplem.
我想指出一些可能可以解决您的问题的问题。我对你的问题有点迷惑,尤其是打开和关闭视图的措辞。我确信您只想根据按下的按钮隐藏和显示视图。
这段代码是不正确的
并且释放和零操作在这里向后
你应该结束
I would like to point out a few issues that may be fix your problem. I am a little lost about your question especially the wording of Opening and Closing a view. I am sure you just want to hide and show a view based on which button is pressed.
This code is incorrect
And the release and nil operations are backwards here
You should end up with