Iphone UIView父方法调用

发布于 2024-11-01 04:26:10 字数 2095 浏览 1 评论 0原文

我遇到了一个问题......请帮忙!

我有一个导航控制器项目。我从根控制器将一个视图推送到堆栈上,其中包含一些信息和 2 个按钮(是、否)。 (它不能是 AlertView)。如果他们按下“是”按钮,我会调用父视图上的方法(使用委托方法)并从堆栈中弹出视图。父级上的方法将新视图推送到堆栈上。我假设在子视图释放后,父方法将保留在内存中,因为该方法存在于父视图上,但是当子视图被释放时,它也会释放在父视图上的方法内创建的所有内容。有没有人有解决方案来响应父视图中子视图上发生的事件,这些事件在子视图被释放后仍然保留?

谢谢!

在头文件中:

#import <UIKit/UIKit.h> 

@protocol decrementDelegate; 
@interface decrement : UIViewController { 
    int currentCount; 
    IBOutlet UILabel *countLabel; 
    id <decrementDelegate> delegate; 
} 
@property (nonatomic, assign) id <decrementDelegate> delegate; 
@end 

@protocol decrementDelegate <NSObject> 
-(void)decrementControllerDidFinish:(decrement *)controller 
        withString:(NSString *)stringValue; 
@end 

在实现文件中:

[self.delegate decrementControllerDidFinish:self 
    withString:countLabel.text]; 
[self.navigationController popViewControllerAnimated:YES];

调用者:

-(void)decrementControllerDidFinish:(decrement *)controller 
    withString:(NSString *)stringValue { 

    // Show our details  
    myNewChildController *viewController = [[myNewChildController alloc] 
        initWithNibName:@"myNewChildController" bundle:nil]; 
    viewController.delegate = self; 
    [self.navigationController pushViewController:viewController animated:YES]; 
    [viewController release]; 
}

使用非委托并且仅调用父级上的方法:

调用者:< /strong>

mySummary *parent = [self.navigationController.viewControllers objectAtIndex:0];
[mySummary setMyAllowOnParent:@"Allowed"]; 
[self.navigationController popViewControllerAnimated:YES]; 

父级:

-(void)setMyAllowOnParent:(NSString *)aAllow { 
newView *viewController = [[newView alloc] initWithNibName:@"newView" bundle:nil];  
[self.navigationController pushViewController:viewController animated:YES]; 
[viewController release]; 
}

当调用方视图被释放时,newView 会因释放错误而崩溃。有谁知道如何解决这个问题?

I'm stuck with an issue.... Please help!

I have a navigation controller project. From the root controller I am pushing a view onto the stack that has some info and 2 buttons (YES, NO). (it can't be an AlertView). If they press the YES button, I call a method on the parent view (using a delegate method) and pop the view from the stack. The method on the parent pushes a new view onto the stack. I assumed the parent method would remain in memory after the deallocation of the child view because the method exists on the parent, but when the child is deallocated it also deallocates everything created inside the method on the parent. Does anyone have a solution for responding to events that happen on a child view in a parent view that will remain after the child is deallocated?

Thanks!

in header file:

#import <UIKit/UIKit.h> 

@protocol decrementDelegate; 
@interface decrement : UIViewController { 
    int currentCount; 
    IBOutlet UILabel *countLabel; 
    id <decrementDelegate> delegate; 
} 
@property (nonatomic, assign) id <decrementDelegate> delegate; 
@end 

@protocol decrementDelegate <NSObject> 
-(void)decrementControllerDidFinish:(decrement *)controller 
        withString:(NSString *)stringValue; 
@end 

in implementation file:

[self.delegate decrementControllerDidFinish:self 
    withString:countLabel.text]; 
[self.navigationController popViewControllerAnimated:YES];

caller:

-(void)decrementControllerDidFinish:(decrement *)controller 
    withString:(NSString *)stringValue { 

    // Show our details  
    myNewChildController *viewController = [[myNewChildController alloc] 
        initWithNibName:@"myNewChildController" bundle:nil]; 
    viewController.delegate = self; 
    [self.navigationController pushViewController:viewController animated:YES]; 
    [viewController release]; 
}

Using non-delegate and just calling a method on the parent:

caller:

mySummary *parent = [self.navigationController.viewControllers objectAtIndex:0];
[mySummary setMyAllowOnParent:@"Allowed"]; 
[self.navigationController popViewControllerAnimated:YES]; 

parent:

-(void)setMyAllowOnParent:(NSString *)aAllow { 
newView *viewController = [[newView alloc] initWithNibName:@"newView" bundle:nil];  
[self.navigationController pushViewController:viewController animated:YES]; 
[viewController release]; 
}

newView crashes with deallocated error when caller view is deallocated. Does anyone have an idea how to resolve this issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦年海沫深 2024-11-08 04:26:10

您是如何创建您的代表的?您没有意外使用retain而不是分配(假设您使用属性来访问它)?因为如果您使用保留,这可能会导致问题。

顺便说一句,您提到了一些关于无法使用的 UIAlertView 的内容,这让我认为您创建了一个与 UIAlertView 具有相似设计的视图。也许以下链接可能有用:

如何使弹出登录窗口与 Objective-C/cocoa-touch 中的 istore 类似

How did you create your delegate? You didn't accidentally used retain instead of assign (assuming you use a property to access it)? Because if you used retain, this might have caused the issue.

By the way, you mention something about a UIAlertView that cannot be used, which leads me to think that you created a view with a similar design as a UIAlertView. Perhaps the following link might be useful:

how can i make popup login window similar as on istore in objective-C/cocoa-touch

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文