开发者

UIActionSheet - class does not implement the 'UIActionSheetDelegate' protocol

I am trying to understand UiActionSheet with a Date Picker.

Getting 2 warnings that I cant seem to clear, see in code at the end of the code section.

warning: Semantic Issue: Sending 'DeveloperTL *' to parameter of incompatible type 'id'

and

warning: Semantic Issue: Sending 'DeveloperTL *' to parameter of incompatible type 'id'

Any ideas how to fix these warnings?

The code I copied from several other examples:

    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 != @"" &&a开发者_如何学Cmp; 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];

    }


Your class in which you are using UIActionSheet, need to confirm with UIActionSheetDelegate protocol

use as below in your .h class.

@interface myClass: UIView <UIActionSheetDelegate>
{

}
@end


In .h file add this

your interface :UIViewController<UIActionSheetDelegate>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜