所以我找到了很多关于制作actionSheet的答案,但是没有多少人遵守ARC的规则。也许那是因为ARC刚刚发布? 无论如何,我正在YouTube(http://www.youtube.com/watch?v=YlXQUQh7Sd4&list=SP53038489615793F7)上关注新的波士顿教程,我在教程中记下了代码,但它不起作用。我稍微调整了一下代码,试图符合ARC规则,但是我遇到了错误。
有人可以通过使用ARC制作actionSheet的正确示例来帮助我吗?
这是我的代码: .H
@interface ViewController : UIViewController <UIActionSheetDelegate>
@property IBOutlet UIButton *button;
-(IBAction) buttonPressed:(id)sender;
@end
的.m
-(IBAction) buttonPressed:(id)sender{
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:@"Want to see an alert?"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:@"Yea, lets see it"
otherButtonTitles:Nil, nil];
[actionSheet showInView:self.view];
}
-(void) actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex{
if (buttonIndex != [actionSheet cancelButtonIndex]) {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"OK, here it is"
message:@"bacon is good umm"
delegate:nil
cancelButtonTitle:@"Done"
otherButtonTitles:nil];
[alert show];
}
}
这是我得到的错误:
2013-12-24 16:23:38.403 BaconUISwitch[4759:70b] -[ViewController buttonPressed]: unrecognized selector sent to instance 0x109238040
2013-12-24 16:23:38.407 BaconUISwitch[4759:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ViewController buttonPressed]: unrecognized selector sent to instance 0x109238040'
*** First throw call stack:
(
0 CoreFoundation 0x000000010188d795 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001015f0991 objc_exception_throw + 43
2 CoreFoundation 0x000000010191ebad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010187f09d ___forwarding___ + 973
4 CoreFoundation 0x000000010187ec48 _CF_forwarding_prep_0 + 120
5 UIKit 0x0000000100254096 -[UIApplication sendAction:to:from:forEvent:] + 80
6 UIKit 0x0000000100254044 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 17
7 UIKit 0x0000000100328450 -[UIControl _sendActionsForEvents:withEvent:] + 203
8 UIKit 0x00000001003279c0 -[UIControl touchesEnded:withEvent:] + 530
9 UIKit 0x0000000100288c15 -[UIWindow _sendTouchesForEvent:] + 701
10 UIKit 0x0000000100289633 -[UIWindow sendEvent:] + 988
11 UIKit 0x0000000100262fa2 -[UIApplication sendEvent:] + 211
12 UIKit 0x0000000100250d7f _UIApplicationHandleEventQueue + 9549
13 CoreFoundation 0x000000010181cec1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
14 CoreFoundation 0x000000010181c792 __CFRunLoopDoSources0 + 242
15 CoreFoundation 0x000000010183861f __CFRunLoopRun + 767
16 CoreFoundation 0x0000000101837f33 CFRunLoopRunSpecific + 467
17 GraphicsServices 0x00000001039943a0 GSEventRunModal + 161
18 UIKit 0x0000000100253043 UIApplicationMain + 1010
19 BaconUISwitch 0x0000000100001bb3 main + 115
20 libdyld.dylib 0x0000000101f1c5fd start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)