I have following query :
SELECT mean("voltage") FROM "cells" WHERE
("cell" = 'Cell 1' or "cell" = 'Cell 2' OR "cell" = 'Cell 3' OR "cell" = 'Cell 4' OR
"cell" = 'Cell 5' OR "cell" = 'Cell 6' OR "cell" = 'Cell 7' OR "cell" = 'Cell 8' OR
"cell" = 'Cell 9' OR "cell" = 'Cell 10' OR "cell" = 'Cell 11' OR "cell" = 'Cell 12' OR
"cell" = 'Cell 13' OR "cell" = 'Cell 14' OR "cell" = 'Cell 15' OR "cell" = 'Cell 16')
AND $timeFilter
GROUP BY time($__interval), "cell" fill(linear)
My issue is that influx sort as string so I get Cell 1 then Cell 10 where I would like to have Cell 1, Cell 2 ... ... , how can I achieve that ?
You can use
ORDER BY SUBSTRING(cell, 6, 12) * 1;
Where SUBSTRING(test, 6, 12) will remove "Cell " from the beginning and * 1 will transform the rest to number.
Related
Can anybody see where i am going wrong? The tableView controller should display either 1 or 4 sections (depending on input from the previous View Controller) along with a dynamic number of rows coming from the array(s).
The program is supposed to populate each section with a different array however i am receiving an Index out of range error in the third case in the Switch statement. The sections and rows are set in the viewdidLoad() method and the selectPic() method changes houseImg variable accordingly.
I'm using Swift 4.
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
if checkData == 0 {
//Inserting one section and filling the cells with the array
saveCount = pupilNames.count
if saveCount > counter{
cell.imageView?.image = houseImg
cell.textLabel?.text = "Pupil Name: \(pupilNames[indexPath.row])"
cell.detailTextLabel?.text = "Score: \(pupilScores[indexPath.row])"
counter = counter+1
}
checkData = 2
return cell
}
else if checkData == 1 {
//Inserting four sections and populate 4 arrays for each section
var countIf: Int = 0
var secondCount: Int = 0
houseCount = 4
if checkCount > houseCont {
switch houseCont {
case 0:
chosenHouse = 1
selectPic()
countIf = pupilNames.count
repeat {
cell.imageView?.image = houseImg
cell.textLabel?.text = "Pupil Name: \(pupilNames[indexPath.row])"
cell.detailTextLabel?.text = "Score: \(pupilScores[indexPath.row])"
secondCount = secondCount+1
} while countIf > secondCount
case 1:
chosenHouse = 2
selectPic()
countIf = secondNames.count
secondCount = 0
repeat {
cell.imageView?.image = houseImg
cell.textLabel?.text = "Pupil Name: \(secondNames[indexPath.row])"
cell.detailTextLabel?.text = "Score: \(secondScores[indexPath.row])"
secondCount = secondCount+1
} while countIf > secondCount
case 2:
chosenHouse = 3
selectPic()
countIf = thirdNames.count
secondCount = 0
repeat {
cell.imageView?.image = houseImg
//*******Error occurring on Pupil Name line *********
cell.textLabel?.text = "Pupil Name: \(thirdNames[indexPath.row])"
cell.detailTextLabel?.text = "Score: \(thirdScores[indexPath.row])"
secondCount = secondCount+1
} while countIf > secondCount
case 3:
chosenHouse = 4
selectPic()
repeat {
cell.imageView?.image = houseImg
cell.textLabel?.text = "Pupil Name: \(fourNames[indexPath.row])"
cell.detailTextLabel?.text = "Score: \(fourScores[indexPath.row])"
secondCount = secondCount+1
}while countIf > secondCount
default:
houseCont = 5
checkData = 2
}
houseCont = houseCont+1
}
}
return cell
}
Edit:
'houseCount' is sent from the previous view controller and contains a value of one or four. 'saveCount' contains a number created by adding up the count of all arrays, this is done in the method that populates the arrays.
saveCount = pupilNames.count+secondNames.count+thirdNames.count+fourNames.count
override func numberOfSections(in tableView: UITableView) -> Int{
return houseCount
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
return saveCount
}
Final Edit: Thanks for all the help everyone, it was a mixture of both answers that helped me to resolve my error. This is my final code that fixed my problem, i removed the if statement and the repeat loop as well as changed some bits of code in order to fix my problem.
else if checkData == 1 {
houseCount = 4
switch indexPath.section {
case 0:
chosenHouse = 1
selectPic()
cell.imageView?.image = houseImg
cell.textLabel?.text = "Pupil Name: \(pupilNames[indexPath.row])"
cell.detailTextLabel?.text = "Score: \(pupilScores[indexPath.row])"
case 1:
chosenHouse = 2
selectPic()
cell.imageView?.image = houseImg
cell.textLabel?.text = "Pupil Name: \(secondNames[indexPath.row])"
cell.detailTextLabel?.text = "Score: \(secondScores[indexPath.row])"
case 2:
chosenHouse = 3
selectPic()
cell.imageView?.image = houseImg
cell.textLabel?.text = "Pupil Name: \(thirdNames[indexPath.row])"
cell.detailTextLabel?.text = "Score: \(thirdScores[indexPath.row])"
case 3:
chosenHouse = 4
selectPic()
//saveCount = fourNames.count
cell.imageView?.image = houseImg
cell.textLabel?.text = "Pupil Name: \(fourNames[indexPath.row])"
cell.detailTextLabel?.text = "Score: \(fourScores[indexPath.row])"
default:
houseCont = 5
checkData = 2
}
houseCont = houseCont+1
}
Looking at the following code, a couple of alarm bells are going off:
chosenHouse = 3
selectPic()
countIf = thirdNames.count
secondCount = 0
repeat {
cell.imageView?.image = houseImg
//*******Error occurring on Pupil Name line *********
cell.textLabel?.text = "Pupil Name: \(thirdNames[indexPath.row])"
cell.detailTextLabel?.text = "Score: \(thirdScores[indexPath.row])"
secondCount = secondCount+1
} while countIf > secondCount
Firstly the use of repeat. The code inside always gets executed at least once. I think this would be an error in the case that thirdNames.count == 0
However, even more oddly, the content of the repeat loop does not change between iterations. You don't do anything that depends on the only thing that changes - secondCount. If countIf were 10, you'd simply assign the same name and score to the same two controls 10 times.
I am not sure but according to me in the last switch statement,when it is executing there is problem while inserting to the sections because it might be exceeding index path row count somehow. Also the way code is written not taking into account the indexPath.section .
i have a function in which i want a big text label and two smaller text label.
The function takes data from a database, and puts them repeatingly into my 3 textlabels.
However, only my default textlabel is visible, Both detailTextLabels doesn't show.
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// Retrieve cell
let cellIdentifier: String = "BasicCell"
let myCell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier)!
// Get the location to be shown
let item: Parsexml = feedItems[indexPath.row] as! Parsexml
// Get references to labels of cell
print(item)
myCell.textLabel!.text = item.name! + " | " + item.address! + " " + item.nr!
myCell.detailTextLabel?.text = "City: " + item.city!
myCell.detailTextLabel?.text = "category: " + item.category!
//Label styling
myCell.textLabel?.textColor = UIColor(white: 1, alpha: 1)
myCell.textLabel?.font = UIFont(name: "HelveticaNeue-Bold", size: 12)
return myCell
}
How do i get my detail text labels to show in swift 3?
That means you have custom cell which has 3 UILables?
if so this line should be like this
let myCell: YouCustomCell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier)!
Then you can use
myCell.1stLable.text = item.name! + " | " + item.address! + " " + item.nr!
myCell.2ndLable.text = "City: " + item.city!
myCell.3rdLable.text = "category: " + item.category!
You must set the cell identifier in storyboard.
I'm making a timetable app using swift.
I load my data from website and put it on a collectionView.
In the first section, I put the day of the week and in the first row, I put the classes and in other cells, I put the data from the web (subject Name, class room...)
If I enter the timetable view, everything is fine at first.
However, if I scroll down and scroll up, some text are printed where they shouldn't be.
This is my collectionView(collectionView: , cellForItemAtIndexPath: )
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
print("\(indexPath.section), \(indexPath.row)")
let dayArray = ["", "월", "화", "수", "목", "금"]
if indexPath.section == 0 {
// Day
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as UICollectionViewCell
var titleLabel = UILabel(frame: CGRectMake(0, 0, cell.bounds.width, cell.bounds.height))
cell.contentView.addSubview(titleLabel)
titleLabel.text = dayArray[indexPath.row]
titleLabel.textAlignment = NSTextAlignment.Center
cell.backgroundColor = mainColor
print("day")
return cell
}
if indexPath.row == 0 {
// index
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as UICollectionViewCell
var titleLabel = UILabel(frame: CGRectMake(0, 0, cell.bounds.width, cell.bounds.height))
cell.contentView.addSubview(titleLabel)
titleLabel.text = String(indexPath.section)
titleLabel.textAlignment = NSTextAlignment.Center
cell.backgroundColor = mainColor
print("time")
return cell
}
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! TimeTableCell
if let timeTableElement = self.timeTable[indexPath.section-1][indexPath.row-1] {
cell.subjectNameLabel.text = timeTableElement.subjectName
cell.subjectNameLabel.adjustsFontSizeToFitWidth = true
cell.classRoomLabel.text = timeTableElement.classRoom
cell.classRoomLabel.adjustsFontSizeToFitWidth = true
} else {
cell.subjectNameLabel.text = ""
cell.classRoomLabel.text = ""
}
cell.backgroundColor = mainColor
print("class")
return cell
}
I'm using a default UICollectionViewCell with adding a label subview to show the day and class time and using a custom TimeTableCell to show the class data.
How can I solve this problem?
Try to use a different 'reuseIdentifier' for TimeTableCell:
change reuse identifier in attributes inspector:
change your code:
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(yourReuseIdentifier, forIndexPath: indexPath) as! TimeTableCell
ps. I suggest to remove the existed titleLabel first and then add the new one, otherwise it will be add again when scrolling down and up.
EDIT
You can 'delete' the titleLabel in two ways:
add a custom cell as well as TimeTableCell(different name and different ReuseIdentifier). as you can see,subjectNameLabel in TimeTableCell will not be add again and again.
set a tag for titleLabel after initialization, and remove it according to the tag.
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as UICollectionViewCell
cell.contentView.viewWithTag(999)!.removeFromSuperview()
var titleLabel = UILabel(frame: CGRectMake(0, 0, cell.bounds.width, cell.bounds.height))
titleLabel.tag = 999
cell.contentView.addSubview(titleLabel)
titleLabel.text = dayArray[indexPath.row]
titleLabel.textAlignment = NSTextAlignment.Center
cell.backgroundColor = mainColor
print("day")
return cell
You need to Remove Title Label before you addd it
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as UICollectionViewCell
// Here find view with tag 999 and remove it from superview
var titleLabel = UILabel(frame: CGRectMake(0, 0, cell.bounds.width, cell.bounds.height))
cell.contentView.addSubview(titleLabel)
titleLabel.tag = 999;
titleLabel.text = String(indexPath.section)
titleLabel.textAlignment = NSTextAlignment.Center
cell.backgroundColor = mainColor
print("time")
return cell
I'm trying to use a custom accessory type (UIImage) for my tableview cell which has a expand/collapse functionality. When user taps a cell the row expands or collpases if parent is tapped again.
The imageview I'm using to set the accessory type is below:
var expandIcon : UIImageView?
expandIcon = UIImageView(frame:CGRectMake(0, 0, 16, 16))
expandIcon!.image = UIImage(named:"expand")
Following code is when user taps a row which if its parent it should epxand or if its already expanded it will collapse.
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cellData = dataForCellAtRowIndex[indexPath.section]!.rows[indexPath.row]
var cell:UITableViewCell!
if isParentCell(indexPath.row) == true {
cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)
cell.textLabel?.text = "test" + String(indexPath.row)
cell.detailTextLabel?.text = "detail"
cell.backgroundColor = UIColor.whiteColor()
cell.accessoryView = expandIcon
}else{
cell = tableView.dequeueReusableCellWithIdentifier("childCell", forIndexPath: indexPath)
cell.backgroundColor = UIColor.lightGrayColor()
cell.textLabel?.text = "child name"
cell.detailTextLabel?.text = "child detail"
cell.accessoryType = UITableViewCellAccessoryType.None
}
return cell
}
The bit that is causing the problem is cell.accessoryView = expandAccessory which causes the UI to freeze and cpu usage goes to 99% as reported by xcode. if i remove cell.accessoryView = expandIcon everything is fine! Why is this happening?
You should implement a function to return an expandIcon and then call it in place of expandIcon variable.
func expandImageView() -> UIImageView {
let expandIcon = UIImageView(frame:CGRectMake(0, 0, 16, 16))
expandIcon.image = UIImage(named:"expand")
return expandIcon
}
cell.accessoryView = expandImageView()
The fix for this as #rmaddy mentioned was the reuse of UIImage view which was causing the UI freeze. Creating a new UIImage for each cell fixed my problem so instead of:
if isParentCell(indexPath.row) == true {
cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)
cell.textLabel?.text = "test" + String(indexPath.row)
cell.detailTextLabel?.text = "detail"
cell.backgroundColor = UIColor.whiteColor()
cell.accessoryView = expandIcon
}
i had to :
if isParentCell(indexPath.row) == true {
cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)
cell.textLabel?.text = "test" + String(indexPath.row)
cell.detailTextLabel?.text = "detail"
cell.backgroundColor = UIColor.whiteColor()
//put the below two lines in a func and return a UIImage
let expandIcon = UIImageView(frame:CGRectMake(0, 0, 16, 16))
expandIcon.image = UIImage(named:"expand")
cell.accessoryView = expandIcon
}
I'm trying to create tableView which is suppose to auto resize the height according to the messageLabel. IOS8 has made this a lot of easier, however i can't seem to achieve this. So far i've created tableViewCell custom class with a xib file looking like below:
and then set the messageLabel.numberOfLines = 0
in the viewController i've set following in viewDidLoad
tableView.estimatedRowHeight = 80.0
tableView.rowHeight = UITableViewAutomaticDimension
and in the end the delegate methods
func tableView(tableView:UITableView, numberOfRowsInSection section:Int)->Int
{
return 1
}
func numberOfSectionsInTableView(tableView:UITableView)->Int
{
return 1
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
var cell = tableView.dequeueReusableCellWithIdentifier("TwitterPlainCell", forIndexPath: indexPath) as! TwitterPlainCell
let url = NSURL(string: "https://pbs.twimg.com/profile_images/507493048062713856/KaWKfdgW.jpeg")
let data = NSData(contentsOfURL: url!) //make sure your image in this url does exist, otherwise unwrap in a if let check
cell.selectionStyle = UITableViewCellSelectionStyle.None
// cell.backgroundColor = UIColor(rgba: "#f6f7f9")
var name = "Olof Kajbjer"
var userName = "#olofmCS"
var topText = "\(name) \(userName)"
var topCount = count(topText)
var userCount = count(userName)
var userNameLocation = topCount - userCount
cell.profileImage.image = UIImage(data: data!)
cell.dateLabel.text = "55m"
var myMutableString = NSMutableAttributedString(string: topText, attributes: [NSFontAttributeName:UIFont(name: "PT Sans", size: 18.0)!])
myMutableString.addAttribute(NSForegroundColorAttributeName, value: UIColor(rgba: "#A6B0B5"), range: NSRange(location:userNameLocation,length:count(userName)))
myMutableString.addAttribute(NSFontAttributeName, value: UIFont(name: "PT Sans", size: 13)!, range: NSRange(location:userNameLocation,length:count(userName)))
// set label Attribute
cell.topLabel.attributedText = myMutableString
cell.messageLabel.text = "I FUCKING LOST AGAINST #olofmCS ON AIM AWP IN OVERTIME... GGgg"
cell.setNeedsUpdateConstraints()
cell.updateConstraintsIfNeeded()
return cell
}
The result of this can seen below, why is it not resizing the cell height?
The issue was related to the bottom constraint i had to set it to >= or another value