gpt4 book ai didi

objective-c - 代表不工作

转载 作者:行者123 更新时间:2023-11-29 05:04:14 24 4
gpt4 key购买 nike

我正在尝试关闭弹出窗口并同时传输数据。我实现了一个委托(delegate) DismissPopoverDelegate 但它无法工作。但没有错误。如果点击保存按钮,它会注册它,并在调用代理之后完成该行。但它不起作用...

AddEventViewController_iPad.h

#import <UIKit/UIKit.h>
#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>
#import <EventKit/EventKit.h>
#import <EventKitUI/EventKitUI.h>
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
#import <Foundation/Foundation.h>
#import "AboutSme.h"
#import "dateViewPopOverViewController_iPad.h"
#import "addPersonViewControllerPopover_iPad.h"
#import "PreviousEventsTableViewControllerPopover_iPad.h"

@interface AddEventViewController_iPad : UIViewController <UITableViewDelegate, UITableViewDataSource, MFMailComposeViewControllerDelegate, UITextFieldDelegate, UIAlertViewDelegate,UIPopoverControllerDelegate,UINavigationControllerDelegate,UIPopoverControllerDelegate,ABPeoplePickerNavigationControllerDelegate, ABNewPersonViewControllerDelegate, DismissPopoverDelegate> {
UIPopoverController *pop;

AddEventViewController_iPad.m

 - (IBAction) selectStartDate:(id) sender {
NSLog(@"Select start date");
dateViewPopOverViewController_iPad *dateViewPopOverViewController = [[dateViewPopOverViewController_iPad alloc] init];
popover2 = [[UIPopoverController alloc] initWithContentViewController:dateViewPopOverViewController];

popover2.delegate = self;
popover2.popoverContentSize = CGSizeMake(320, 460);

CGRect rect = CGRectMake(790, 170, 175, 300);

[popover2 presentPopoverFromRect:rect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];

[dateViewPopOverViewController release];

/*
if (dateViewController == nil) {
dateViewController = [[DateViewController_iPad alloc] initWithNibName:@"DateViewController_iPad" bundle:nil];
}

[self presentModalViewController:dateViewController animated:YES];

[dateViewController retain];
*/
}

- (void) dismissWithData:(NSString *)data
{
NSLog(@"%@", data);

[pop dismissPopoverAnimated:YES];
[pop release];
}

dateViewPopOverViewController_iPad.h

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@protocol DismissPopoverDelegate <NSObject>
@required
- (void) dismissWithData:(NSString *)data;

@end
@interface dateViewPopOverViewController_iPad : UIViewController {
IBOutlet UIDatePicker *datePicker;
IBOutlet UISegmentedControl *segmentedBar;
IBOutlet UILabel *startLabel;
IBOutlet UILabel *endLabel;
IBOutlet UISwitch *allDaySwitch;
NSDate *startDate;
NSDate *endDate;
NSDate *now;
NSDateFormatter *dateFormatter;
id<DismissPopoverDelegate> delegate;
}

@property (retain) id delegate;
- (void) dismissWithData:(NSString *)data;



dateViewPopOverViewController_iPad.m

@implementation dateViewPopOverViewController_iPad

@synthesize startDate, endDate, datePicker, segmentedBar, startLabel, endLabel, now, allDaySwitch, delegate;

- (IBAction) save:(id)sender {
if ([self startDateIsValid] && [self endDateIsValid]) {
//[[self parentViewController] setDatesForEvent:startDate eventEndDate:endDate allDay:[allDaySwitch isOn]];
// [self dismissModalViewControllerAnimated:YES];
NSLog(@"works");
[self.delegate dismissWithData:@"Some text from popover"];
NSLog(@"works1");
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Ooops!" message:@"Please check the dates! Remember the end date must occur after the start date for the event to save." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
}

最佳答案

包含 .h 文件时存在循环引用。

dateViewPopOverViewController_iPad.h 包含 AddEventViewController_iPad.hAddEventViewController_iPad.h 包含 dateViewPopOverViewController_iPad.h,这会导致编译器抛出错误。

使用协议(protocol)的目的之一是避免这种循环引用。从 AddEventViewController_iPad.h 文件中删除 dateViewPopOverViewController_iPad.h 可能会解决该问题

关于objective-c - 代表不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6008931/

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