【发布时间】:2017-02-18 06:25:06
【问题描述】:
所以我将 Xcode 和 GitHub 项目代码升级到 swift 3.0(我的项目在 Obj C 中,而我从 GitHub 使用的一些 pod 是在 Swift 中)。我遇到了一堆错误,现在我被困在这些错误上。由于某种原因,我的 floatActionButton (git here) 的数据源和委托现在不起作用。我尝试在情节提要上以编程方式设置dataSource 和delegate,但没有成功。
错误:
在“LiquidFloatingActionButton *”类型的对象上找不到属性“dataSource”
在“LiquidFloatingActionButton *”类型的对象上找不到属性“delegate”
我相信如果我解决了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];
}
Pod 文件:
# 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
以下更新
我最终使用了this 项目,因为原始 GitHub 没有得到修复,感谢所有帮助,如果有人解决了这个问题,请让这里的每个人都知道!
【问题讨论】:
-
那是 Objective-C 代码,不是 Swift 3 代码。
-
@rmaddy 啊哈!该组件已升级到 Swift 3.0,而不是 OP 的代码。
-
@rmaddy 我的项目在目标 c 中,正在使用的 GitHub 是在 Swift 中。对不起,我没有提到这个。
-
可以显示 Podfile 的内容吗?
-
是的,刚刚更新了问题
标签: ios objective-c git delegates datasource