将UITabBarDelegate设置为UIViewController时应用程序崩溃

时间:2016-10-17 06:25:51

标签: ios swift xcode

当我尝试在Exception in thread "main" java.sql.SQLException: org.apache.hadoop.hbase.client.RetriesExhaustedException: Failed after attempts=36, exceptions: Mon Oct 17 11:50:18 IST 2016, null, java.net.SocketTimeoutException: callTimeout=60000, callDuration=80992: row 'SYSTEM:CATALOG,,' on table 'hbase:meta' at region=hbase:meta,,1.1588230740, hostname=HOSTNAME,16201,1476683863488, seqNum=0 的子类中将UITabBarDelegate设置为self时,我的应用程序崩溃了。我有一个UIViewController,其中有几个TabItems链接到View Controllers。其中一个视图控制器是UITabBarViewController。我在HomeViewController中有以下代码:

HomeViewController

如果我删除class HomeViewController: UIViewController, UITabBarDelegate { override func viewDidLoad() { super.viewDidLoad() self.tabBarController?.tabBar.translucent = false self.extendedLayoutIncludesOpaqueBars = true self.tabBarController?.tabBar.delegate = self //This is causing crash } } 行,一切正常,我的tabBar按预期运行,但当我重新添加该行时,我遇到以下崩溃:

self.tabBarController?.tabBar.delegate = self

不完全确定如何解决此问题。在SO上找到了一些其他的答案,但他们似乎仍然不清楚这个过程是什么使这个工作。

谢谢!

1 个答案:

答案 0 :(得分:1)

您的UITabBarViewController已经是UITabBar的委托。不要将viewController作为tabBarDelegate,而是使用tabBarViewController并将逻辑放在那里。

你可以这样做。在tabBarViewController的didSelectItem委托方法

- (PDFDocument *)pdfDocument {
    // create a page
    PDFDocument *document = [[PDFDocument alloc] initWithURL:[NSURL fileURLWithPath:@"/Users/test/Downloads/Eticket.pdf"]];

    NSMutableDictionary *popupDictionary = [[NSMutableDictionary alloc] init];

    [popupDictionary setObject:@"/Popup" forKey:kPDFAnnotationKey_Subtype];
    [popupDictionary setObject:[NSColor redColor] forKey:kPDFAnnotationKey_Color];
    [popupDictionary setObject:@"Hello" forKey:kPDFAnnotationKey_Contents];

    NSValue *rectValue = [NSValue valueWithRect:NSMakeRect(100, 100, 40, 40)];
    [popupDictionary setObject:rectValue forKey:kPDFAnnotationKey_Rect];

    PDFAnnotation *textAnnotation = [[PDFAnnotation alloc] initWithDictionary: popupDictionary forPage: [document pageAtIndex:0]];
    [[document pageAtIndex:0] addAnnotation:textAnnotation];    // add it to the PDF document
    return document;
}