gpt4 book ai didi

iphone - 自定义 View Controller 委托(delegate)不起作用

转载 作者:行者123 更新时间:2023-11-29 04:51:17 25 4
gpt4 key购买 nike

我的自定义委托(delegate)有问题,不知道为什么不起作用。我想将委托(delegate)传递到主视图,以便在添加新记录后它会自动推送到详细 View 。

不确定我错过了什么。我正在做与 Storyboard和 iOS 5 的所有链接。

感谢您的浏览并感谢所有评论

addnote.h

#import <UIKit/UIKit.h>
#import "memoView.h"

@protocol addNoteDelegate;
@interface addNote : UIViewController
{
IBOutlet UITextField *memoNameTextField;
IBOutlet UITextField *memoCommentsTextField;
id <addNoteDelegate> delegate;
}

@property (nonatomic,assign) id <addNoteDelegate> delegate;


- (IBAction)done:(id)sender;
- (IBAction)cancel:(id)sender;
@end

@protocol addNoteDelegate <NSObject>
-(void)addNoteDidFinish:(addNote *)controller;
-(void)addNoteDidCancel:(addNote *)controller;
@end

addnote.m

-(IBAction)add:(id)sender
{
[[self delegate] addNoteDidFinish:self];
}

mainview.h

#import <UIKit/UIKit.h>
#import "addNote.h"

@interface mainView : UITableViewController<NSFetchedResultsControllerDelegate, addNoteDelegate>
{
}

@property (nonatomic, retain) NSArray *memoInfo;
@property (nonatomic, retain) NSFetchedResultsController *fetchedResultsController;
@property (nonatomic, retain) NSManagedObjectContext *ObjectContext;

-(IBAction)backToMain:(id)sender;
- (IBAction)addNote:(id)sender;
@end

mainView.m

-(IBAction)addNote:(id)sender
{
addNote *addingNote = [[addNote alloc] init];
addingNote.delegate = self;
[self performSegueWithIdentifier:@"addNote" sender:self];
}

- (void)addNoteDidFinish:(addNote *)controller{
//PUSH TO NEXT VIEW

[[self navigationController] dismissModalViewControllerAnimated:YES];
}

最佳答案

 @protocol addNoteDelegate <NSObject>
-(void)addNoteDidFinish:(addNote *)controller;
-(void)addNoteDidCancel:(addNote *)controller;
@end

@interface addNote : UIViewController
{
IBOutlet UITextField *memoNameTextField;
IBOutlet UITextField *memoCommentsTextField;
id <addNoteDelegate> delegate;
}

@property (nonatomic,assign) id <addNoteDelegate> delegate;


- (IBAction)done:(id)sender;
- (IBAction)cancel:(id)sender;
@end

和:

[self dismissModalViewControllerAnimated:YES];

不是:

[[self navigationController] dismissModalViewControllerAnimated:YES];

关于iphone - 自定义 View Controller 委托(delegate)不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8783492/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com