所以我将 Xcode 和 GitHub 项目代码升级到 swift 3.0(我的项目在 Obj C 中,我从 GitHub 使用的一些 pod 在 Swift 中)。我遇到了一堆错误,现在我被困在这些错误上了。出于某种原因,我的数据源和 floatingActionButton ( git here ) 的委托(delegate)现在不起作用。我尝试以编程方式和 Storyboard上设置 dataSource
和 delegate
,但没有成功。
错误:
Property 'dataSource' not found on object of type 'LiquidFloatingActionButton *'
Property 'delegate' not found on object of type 'LiquidFloatingActionButton *'
我相信如果我弄清楚 dataSource
和 delegate
问题,那么它会修复下面的颜色错误。
.h:
#import <UIKit/UIKit.h>
#import "ProductContentViewController.h"
#import "LiquidFloatingActionButton-swift.h"
@interface SetScreenViewController : UIViewController
<UIPageViewControllerDataSource, LiquidFloatingActionButtonDelegate, LiquidFloatingActionButtonDataSource>
...
@end
.m:
#import "LiquidFloatingActionButton-Swift.h"
LiquidFloatingActionButton *floatingActionButton;
NSMutableArray *liquidCells;
bool *closeFloatingButtons;
NSString *videoToWatchURL;
- (void)addLiquidButton{
//Grabs the coordinates bottom right of the screen
float X_Co = self.view.frame.size.width - 50;
float Y_Co = self.view.frame.size.height - 50;
//i subtract 10 so the button will be placed a little bit out
X_Co = X_Co - 10;
Y_Co = Y_Co - 10;
//I create each cell and set the image for each button
liquidCells = [[NSMutableArray alloc] init];
[liquidCells addObject:[[LiquidFloatingCell alloc]initWithIcon:[UIImage imageNamed:@".png"]]];
[liquidCells addObject:[[LiquidFloatingCell alloc]initWithIcon:[UIImage imageNamed:@".png"]]];
[liquidCells addObject:[[LiquidFloatingCell alloc]initWithIcon:[UIImage imageNamed:@".png"]]];
[liquidCells addObject:[[LiquidFloatingCell alloc]initWithIcon:[UIImage imageNamed:@".png"]]];
[liquidCells addObject:[[LiquidFloatingCell alloc]initWithIcon:[UIImage imageNamed:@".png"]]];
[liquidCells addObject:[[LiquidFloatingCell alloc]initWithIcon:[UIImage imageNamed:@".png"]]];
//Sets the floating button at the loaction provided
floatingActionButton = [[LiquidFloatingActionButton alloc] initWithFrame:CGRectMake(X_Co, Y_Co, 50, 50)];
floatingActionButton.dataSource = self;//Error here
floatingActionButton.delegate = self;//and here.
//I set the color of the floating button
floatingActionButton.color = [self colorWithHexString:@"01b8eb"];
//Enables the user interaction fuction to true so itll open or close
floatingActionButton.userInteractionEnabled = YES;
//Adds the flaoting button to the view
[self.view addSubview:floatingActionButton];
}
-(NSInteger)numberOfCells:(LiquidFloatingActionButton *)liquidFloatingActionButton{
return liquidCells.count;
}
-(LiquidFloatingCell *)cellForIndex:(NSInteger)index{
return [liquidCells objectAtIndex:index];
}
播客文件:
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
target 'Whats New' do
# Uncomment this line if you're using Swift or would like to use dynamic frameworks
# use_frameworks!
# Pods for Whats New
target 'Whats NewTests' do
inherit! :search_paths
# Pods for testing
end
target 'Whats NewUITests' do
inherit! :search_paths
# Pods for testing
end
pod 'CRToast', '~> 0.0.7'
pod "LiquidFloatingActionButton"
pod 'DGActivityIndicatorView'
pod 'M13ProgressSuite'
pod 'SDWebImage', '~>3.8'
pod 'FSCalendar'
use_frameworks!
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '3.0'
end
end
end
end
UPDATE BELOW
我最终使用了 this项目,因为原始的 GitHub 没有被修复,感谢所有的帮助,如果有人解决了这个问题,请让这里的每个人都知道!
最佳答案
如果 swift @protocols
不是用 @objc
定义的,那么你不能在 objective-c 中访问它们,
例如
@objc public protocol xxxxxxxxxxxDelegate {
func functionOne()
func functionSecond()
}
关于ios - 无法配置数据源和委托(delegate),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39947980/