gpt4 book ai didi

iphone - UIActionSheet - 类未实现 'UIActionSheetDelegate' 协议(protocol)

转载 作者:行者123 更新时间:2023-12-03 20:25:54 26 4
gpt4 key购买 nike

我正在尝试使用日期选择器来理解 UiActionSheet。

收到 2 个我似乎无法清除的警告,请参阅代码部分末尾的代码。

警告:语义问题:将“DeveloperTL *”发送到不兼容类型“id”的参数

警告:语义问题:将“DeveloperTL *”发送到不兼容类型“id”的参数

有什么想法可以解决这些警告吗?

我从其他几个示例复制的代码:

    define kPickerTag 200
define SelectButtonIndex 1
define CancelButtonIndex 2
NSString *strPrintDate;


- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex != [actionSheet cancelButtonIndex]) {

//set Date formatter
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MM/dd/YYYY h:mm a"];

//Gets our picker
UIDatePicker *ourDatePicker = (UIDatePicker *) [actionSheet viewWithTag:kPickerTag];

NSDate *selectedDate = [ourDatePicker date];

NSString *msg = [[NSString alloc] initWithFormat:@"The date that you had selected was, %@", [formatter stringFromDate:selectedDate]];
[formatter release];

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Date" message:msg delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
[alert show];
[alert release];
[msg release];
}
}




-(void)willPresentActionSheet:(UIActionSheet *)actionSheet {

UIDatePicker *pickerView = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 50, 100, 116)];

[pickerView setTag:kPickerTag];

[pickerView setDatePickerMode:UIDatePickerModeDate];

if( strPrintDate != @"" && strPrintDate != nil )
{
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"MMM-dd-yyyy"];

NSDate *pickerdate = [dateFormat dateFromString:strPrintDate];
[pickerView setDate:pickerdate animated:YES];
[dateFormat release];
}

[actionSheet addSubview:pickerView];

[pickerView release];

NSArray *subViews = [actionSheet subviews];

[[subViews objectAtIndex: SelectButtonIndex] setFrame:CGRectMake(20, 266, 280, 46)];
[[subViews objectAtIndex:CancelButtonIndex] setFrame:CGRectMake(20, 317, 280, 46)];

}


- (IBAction)butn1 {



UIActionSheet *asheet = [[UIActionSheet alloc]
initWithTitle:@"Pick the date you want to see." delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Select", nil];

// THIS IS THE ERROR MESSAGE:
// **warning: Semantic Issue: Sending 'DeveloperTL *' to parameter of incompatible type // 'id<UIActionSheetDelegate>'**


[asheet showInView:[self.view superview]];

[asheet setFrame:CGRectMake(0, 117, 320, 383)];
[asheet release];

}

最佳答案

您正在使用UIActionSheet的类,需要使用UIActionSheetDelegate协议(protocol)进行确认

在您的 .h 类中按如下方式使用。

@interface myClass: UIView <UIActionSheetDelegate>
{

}
@end

关于iphone - UIActionSheet - 类未实现 'UIActionSheetDelegate' 协议(protocol),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6454871/

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