UIActionSheet - 类没有实现'UIActionSheetDelegate'协议

时间:2011-06-23 13:30:29

标签: iphone uidatepicker uiactionsheet

我试图了解带有日期选择器的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];

    }

2 个答案:

答案 0 :(得分:7)

您正在使用UIActionSheet的课程,需要使用UIActionSheetDelegate协议进行确认

在.h课程中使用如下。

@interface myClass: UIView <UIActionSheetDelegate>
{

}
@end

答案 1 :(得分:0)

在.h文件中添加此

your interface :UIViewController<UIActionSheetDelegate>