我将我的操作系统更新到 El Capitan,同时我猜 XCode 也更新了(现在是 7.2),在此之前,当我在模拟器中运行我的代码时它运行良好。现在,当我尝试在选项卡式应用程序中的第一个 View Controller 中运行日历代码时,出现错误“使用未解析的标识符‘SACalendar’”,但其他一切似乎都正常。我不确定是否有任何语法更改或更新有什么问题,但这似乎是一个常见问题,所以我尝试查看其他一些帖子,但找不到与我的问题相关的任何内容。有谁知道发生了什么事?下面的代码有错误,SACalendar 是一个通过桥接 header 包含的 .m 文件。桥接 header 确实包含所有必需的 .h 文件,包括 SACalendar.h
import UIKit
class FirstViewController: UIViewController, SACalendarDelegate {
override func viewDidLoad() {
super.viewDidLoad()
/*
* Smooth scrolling in vertical direction
* - to change to horizontal, change the scrollDirection to ScrollDirectionHorizontal
* - to use paging scrolling, change pagingEnabled to true
* - the calendar works with any size
*/
//Get the width and the height of the device
let frameWidth = self.view!.frame.size.width
let frameHeight = self.view!.frame.size.height - 110
var calendar : SACalendar = SACalendar(frame: CGRectMake(0, 80, frameWidth, frameHeight), scrollDirection: ScrollDirectionVertical, pagingEnabled: true)
//error occurs due to the SACalendar on the righthand side of assignment operator
calendar.delegate = self
self.view!.addSubview(calendar)
}
}
桥接头:
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//
#ifndef YogaAdmin_Bridging_Header_h
#define YogaAdmin_Bridging_Header_h
#import "DateUtil.h"
#import "DMLazyScrollView.h"
#import "SACalendar.h"
#import "SACalendarCell.h"
#import "SACalendarConstants.h"
#endif
最佳答案
我遇到了同样的问题,我发现委托(delegate)函数名称与类名称相同,这在 swift 中造成了问题,所以我通过更改委托(delegate)函数名称解决了这个问题。
-(void) SACalendar:(SACalendar*)calendar didDisplayCalendarForMonth:(int)month year:(int)year;
-(void) SACalendar:(SACalendar*)calendar didSelectDate:(int)day month:(int)month year:(int)year;
TO
-(void) Calendar:(SACalendar*)calendar didDisplayCalendarForMonth:(int)month year:(int)year;
-(void) Calendar:(SACalendar*)calendar didSelectDate:(int)day month:(int)month year:(int)year;
并将调用委托(delegate)函数的 SACalendar 替换为 Calendar。
谢谢
关于ios - Swift - 更新后使用未解析的标识符错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34477820/