自iOS 7推出以来,对Objective-C进行了大量改进和更改。我在下面创建了UIActionSheet
,并将delegate
分配给self
,以便我可以按下每个按钮来完成操作。
- (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>
的{{1}}文本中收到以下警告:self
。我假设它说我正在做“低效率”的事情,我想知道需要改变什么才能让这个警告不出现。
答案 0 :(得分:2)
您的班级似乎未向UIActionSheetDelegate
协议确认。
检查您是否有类似
的内容@interface YourClass () <UIActionSheetDelegate>