Question

Since the introduction of iOS 7, a lot of improvements and changes were made to Objective-C. I've created a UIActionSheet below and assigned the delegate to self so that I could program each button press to complete an action.

- (IBAction)sortButton
{
    UIActionSheet *sortSheet = [[UIActionSheet alloc]
                                initWithTitle:@"Sort By"
                                delegate:self
                                cancelButtonTitle:@"Cancel"
                                destructiveButtonTitle:@"Featured"
                                otherButtonTitles:@"Price", @"Brand", nil];

    [sortSheet showInView:self.view];
}

This is the code I use to check against what the user did when they clicked on a specific button in the UIAlertView:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if(buttonIndex == 0)
    {
        UIAlertView *dueDateAlert = [[UIAlertView alloc]
                                     initWithTitle:@"Featured"
                                     message:@"This button formats the list for items based on Feature."
                                     delegate:nil
                                     cancelButtonTitle:nil
                                     otherButtonTitles:@"Ok", nil];

        [dueDateAlert show];
    }

    else if(buttonIndex == 1)
    {
        UIAlertView *creationDateAlert = [[UIAlertView alloc]
                                          initWithTitle:@"Price"
                                          message:@"This button formats the list for items based on Price."
                                          delegate:nil
                                          cancelButtonTitle:nil
                                          otherButtonTitles:@"Ok", nil];

        [creationDateAlert show];
    }

    else if(buttonIndex == 2)
    {
        UIAlertView *subjectAlert = [[UIAlertView alloc]
                                     initWithTitle:@"Brand"
                                     message:@"This button formats the list for items based on Brand."
                                     delegate:nil
                                     cancelButtonTitle:nil
                                     otherButtonTitles:@"Ok", nil];

        [subjectAlert show];
    }
}

When I run this code, I get the following Warning: Sending SecondViewController *const_strong to parameter of incomplete type 'id<UIActionSheetDelegate> on the self text in the creation of the UIActionSheet. I'm assuming it's saying that I'm doing something "inefficiently", and I was wondering what needs to change in order for this warning not to appear.

Était-ce utile?

La solution

It seems that your class does not confirm to UIActionSheetDelegate protocol.

Check that you have something like

@interface YourClass () <UIActionSheetDelegate>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top