自从 iOS 7 推出以来,Objective-C 进行了大量改进和更改。我创建了一个 UIActionSheet
下面并分配了delegate
至 self
这样我就可以对每次按下按钮来完成一个 Action 进行编程。
- (IBAction)sortButton
{
UIActionSheet *sortSheet = [[UIActionSheet alloc]
initWithTitle:@"Sort By"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:@"Featured"
otherButtonTitles:@"Price", @"Brand", nil];
[sortSheet showInView:self.view];
}
这是我用来检查用户在单击 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];
}
}
当我运行这段代码时,我收到以下警告:Sending SecondViewController *const_strong to parameter of incomplete type 'id<UIActionSheetDelegate>
在 self
上创作中的文字UIActionSheet
.我假设它是在说我正在“低效”地做某事,我想知道需要更改哪些内容才能使此警告不出现。
最佳答案
您的类似乎没有确认 UIActionSheetDelegate
协议(protocol)。
检查你有类似的东西
@interface YourClass () <UIActionSheetDelegate>
关于ios - UIActionSheet 委托(delegate) self 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22263446/