如何UITableView在Swift 3中清除它并清除它.
我已经完成了之前的线程,但我仍然得到了白色背景.
从我的代码中可以看出,我尝试了各种方法:
override func viewDidLoad() {
self.communitiesTableView.delegate = self
self.communitiesTableView.dataSource = self
let background = CAGradientLayer().bespokeColor()
background.frame = self.view.bounds
// view.addSubview(background)
super.viewDidLoad()
// Do any additional setup after loading the view.
}
Run Code Online (Sandbox Code Playgroud)
并在我的单元格表功能:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let title = self.communities[indexPath.row]
let cell = UITableViewCell()
cell.textLabel?.text = title
cell.textLabel?.font = UIFont(name: "Avenir", size: 12)
cell.textLabel?.textColor = UIColor.red
cell.textLabel?.backgroundColor = UIColor.clear
cell.contentView.backgroundColor = UIColor.clear
communitiesTableView.backgroundColor = UIColor.clear
cell.layer.backgroundColor = UIColor.clear.cgColor
return …Run Code Online (Sandbox Code Playgroud) 我希望能够在我的右侧滑动,ViewController这将显示另一个视图控制器,CommunitiesViewController.
我已经查看了其他线程并找到了一些方法,但我相信它们适用于Swift 2.
这是我在我的代码中使用的代码ViewController:
override func viewDidLoad() {
super.viewDidLoad()
let swipeRight = UISwipeGestureRecognizer(target: self, action: Selector(("respondToSwipeGesture")))
swipeRight.direction = UISwipeGestureRecognizerDirection.right
self.view.addGestureRecognizer(swipeRight)
}
func respondToSwipeGesture(gesture: UIGestureRecognizer) {
print ("Swiped right")
if let swipeGesture = gesture as? UISwipeGestureRecognizer {
switch swipeGesture.direction {
case UISwipeGestureRecognizerDirection.right:
//change view controllers
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let resultViewController = storyBoard.instantiateViewController(withIdentifier: "CommunitiesID") as! CommunitiesViewController
self.present(resultViewController, animated:true, completion:nil)
default:
break
}
}
}
Run Code Online (Sandbox Code Playgroud)
我给CommunitiesViewController了一个故事板ID CommunitiesID.
但这不起作用,当我向右滑动时出现以下错误,应用程序崩溃:
libc …
我一直在关注非常简单的iOS图表教程。
我的图表中的值现在可以正确显示,但是底部的标签没有显示。
override func viewDidLoad() {
results = ["Won", "Drawn", "Lost"]
let games = [totalWins, totalDraws, totalLosses]
setChart(dataPoints: results, values: games)
}
// CHART FUNCTION ************
func setChart(dataPoints: [String], values: [Double]){
barChartView.noDataText = "you need to provide some data for the chart."
var dataEntries: [BarChartDataEntry] = Array()
for i in 0..<dataPoints.count {
let dataEntry = BarChartDataEntry(x: Double(i), y: values[i])
dataEntries.append(dataEntry)
}
let chartDataSet = BarChartDataSet(values: dataEntries, label: "Games Played")
//let chartData = BarChartData(xVals: self.results, dataSet: dataEntries)
let chartData = BarChartData() …Run Code Online (Sandbox Code Playgroud) 在这个场景中,我有:球员、梦幻足球联赛(社区)和结果。
1 个用户可以加入多个幻想联盟。
我当前的结构为:
create table players (id int, email, display_name)
create table communities (id int, name, password, admin_email)
create table community_players (community_id, player_id)
Run Code Online (Sandbox Code Playgroud)
我现在需要为每个社区创建一个结果表。我刚在想:
create table results (player1_id, player1_points, player1_goals_scored, player2_id, player2_points, player2_goals_scored, date, community_id)
Run Code Online (Sandbox Code Playgroud)
我担心这张桌子最终会变得很大。因此,当我去查询它的统计数据(即谁击败了谁、进球数、失球数等)时,它最终会变得非常慢。
我的想法是:
我是否应该为创建的每个社区“即时”创建一个结果表?
create table results_community_name (player1_id, player1_points, player1_goals_scored, player2_id, player2_points, player2_goals_scored, date, community_id)
Run Code Online (Sandbox Code Playgroud) 我有一个测验资源,用于定义测验中的问题和答案。
BelongsTo 字段用于选择该测验的创建者 - 它将这些信息从我的用户表中提取出来。但是,我只想提取“role_id”为 1 或 2 的用户。
我正在尝试使用相关功能,但它似乎不想承认它的存在。
我的测验资源:
class Quiz extends Resource
{
/**
* The model the resource corresponds to.
*
* @var string
*/
public static $model = 'App\Quiz\Quiz';
public function fields(Request $request)
{
return [
...
BelongsTo::make('User', 'users','\App\Nova\User')
->display(function($user){
return $user->first_name . ' ' . $user->last_name;
}),
...
];
}
}
Run Code Online (Sandbox Code Playgroud)
我的 Nova 用户模型:
class User extends Resource
{
public static $model = 'App\Account\User';
public static function relatableQuizzes(NovaRequest $request, $query)
{
return $query->where('role_id', 1); …Run Code Online (Sandbox Code Playgroud) 我已经使用iPhone SE视图在Xcode中布置了我的应用程序.按钮等都在测试它们应该如何.
然而,当我在大屏幕上进行测试时,即iPhone 7会发生一些奇怪的事情.
1)按钮拥抱右侧,即使我将约束设置为距离边距为20px
其次,我应用于我的按钮的渐变似乎在这个实例中停止了按钮的3/4:
它与按钮的每个实例中调用的代码相同:
let orangeGradient = CAGradientLayer().orangeButtonColor()
orangeGradient.frame = self.joinCommunityButton.bounds
self.joinCommunityButton.layer.insertSublayer(orangeGradient, at: 0)
extension CAGradientLayer {
func bespokeColor() -> CAGradientLayer {
let topColor = UIColor(red: (46/255.0), green: (63/255.0),blue: (81/255.0), alpha: 1)
let bottomColor = UIColor(red: (22/255.0), green: (31/255.0),blue: (41/255.0), alpha: 1)
let gradientColors: [CGColor] = [topColor.cgColor, bottomColor.cgColor]
let gradientLocations: [Float] = [0.0, 1.0]
let gradientLayer: CAGradientLayer = CAGradientLayer()
gradientLayer.colors = gradientColors
gradientLayer.locations = gradientLocations as [NSNumber]?
return gradientLayer
}
func orangeButtonColor() -> CAGradientLayer {
let topColor …Run Code Online (Sandbox Code Playgroud) ios ×4
swift ×4
charts ×1
database ×1
ddl ×1
eloquent ×1
ios-charts ×1
iphone ×1
laravel ×1
laravel-5 ×1
laravel-nova ×1
mysql ×1
swift3 ×1
uitableview ×1
xcode ×1