我已經搜索並搜索了該板,並且無法弄清楚這一點。它必須是一些簡單而恰到好處的東西。當從UIViewController文件移動到單獨的類文件時,UIActionSheet代碼崩潰
我想清理我的代碼,並使其更加可重用。我正在從UIViewController獲取一些UIActionSheet代碼,並創建它自己的目標文件。工作正常,直到我添加UIActionSheetDelegate方法。
當按下按鈕而不是觸發actionSheetCancel方法時,它會崩潰而沒有堆棧跟蹤。每次。
我的代碼如下。任何幫助,將不勝感激。我的猜測是因爲我沒有使用xcode storyboard工具來將東西連接在一起,但我認爲這是合法的。
egcTestSheet.h:
#import <UIKit/UIKit.h>
@interface egcTestSheet : NSObject <UIActionSheetDelegate> {
}
- (void) showSheet:(UITabBar *) tabBar
displayTitle:(NSString *) name;
@end
egcTestSheet.m從一個UIViewController對象
#import "egcTestSheet.h"
@implementation egcTestSheet
-(void) showSheet:(UITabBar *)tabBar displayTitle:(NSString *)name{
UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle:name
delegate:self
cancelButtonTitle:@"Done"
destructiveButtonTitle:@"Cancel"otherButtonTitles:nil];
[menu showFromTabBar:tabBar];
[menu setBounds:CGRectMake(0,0,320, 700)];
}
// actionsheet delegate protocol item
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex: (NSInteger)buttonIndex{
NSLog(@"button index = %d", buttonIndex);
}
- (void)actionSheetCancel:(UIActionSheet *)actionSheet{
NSLog(@"in action canceled method");
}
@end
調用代碼:
egcTestSheet *sheet = [[egcTestSheet alloc] init];
[sheet showSheet:self.tabBarController.tabBar displayTitle:@"new test"];
哪一行是罪魁禍首? –