I have an array of strings and I am populating a table view with the array data. I want the table view to display 1 in the first row, 2 in the second row, 3 in the third row. I have done this before but it is not working now. Every time I run the app, it displays the number of elements in the array in every row. What am I doing wrong?func numPick() -> Int {
var num: Int = 0
for _ in myRoster! {
num+=1
}
return num
}
Post not yet marked as solved
I have two arrays of strings and two table views. In one table view I am using swipe to remove feature. Both arrays hold the same data. When I swipe to remove, I want to remove the same string from the other array also. The strings will have different indexes in the arrays and one array will have a prefix and a suffix. How do I do this?var myArray1: [String] = ["1. Adam, Blazers", "2. Jack, Dare Devils", "3. Steven, Tigers", "4. Donald, Sharks",
"5. Aaron, Cyclones"]
var myArray2: [String] = ["1. Donald, Sharks - QB", "2. Aaron, Cyclones - RB", "3. Adam, Blazers - WR",
"4 Jack, Dare Devils - WR", "5. Steven, Tigers - TE"]I swipe the row in the table that holds "3. Adam, Blazers - WR" from myArray2. I want to remove the string from the myArray1 that holds the string "1. Adam, Blazers". In other words, I swipe the row in myArray2 at index 2 and I want it to remove the string in myArray1 at index 1. How do I do that?
I have a table view and an array of strings. When I swipe a row, I want to add the clicked string to an array of strings. How do I get the value stored in the table view row. I have it set up like this:import UIKit
var myStringArray: [String]?
var someStringArray: [String] = ["Hot Dogs", "Soda", "Chips", "Hamburgers", "Plates", "Dessert", "Napkins", "Fruit",
"Potatoe Salad", "Brats"]
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return someStringArray.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath as IndexPath)
cell.textLabel?.text = someStringArray[indexPath.row]
cell.textLabel?.adjustsFontSizeToFitWidth = true
cell.textLabel?.font = UIFont.systemFont(ofSize: 22)
return cell
}
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let object: String = someStringArray[indexPath.row]
let add = UIContextualAction(style: .normal, title: "Add") { (contextualAction, view, actionPerformed: @escaping (Bool) -> Void) in
let alert = UIAlertController(title: "Add ", message: "Are you sure you want to add '\(object)' to your list?", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "No", style: .cancel, handler: { (alertAction) in
actionPerformed(false)
}))
alert.addAction(UIAlertAction(title: "Yes", style: .destructive, handler: { (alertAction) in
self.addObject()
}))
self.present(alert, animated: true)
}
return UISwipeActionsConfiguration(actions: [add, taken])
}
func addObject(index: Int) {
let index = table.indexPathForSelectedRow
let _index = (index?[someStringArray.hashValue])!
if myStringArray!.isEmpty {
myStringArray?.insert(someStringArray[_index], at: 0)
} else {
myStringArray?.append(someStringArray[_index])
}
}
Post not yet marked as solved
I created a custom cell, created an instance of a struct, and set the text properties in the custom cell class.import UIKit
class CustomTableViewCell: UITableViewCell {
var my_Data = MyData()
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
@IBOutlet weak var cellLoanName: UILabel!
@IBOutlet weak var cellMonthlyPayment: UILabel!
@IBOutlet weak var cellBalance: UILabel!
@IBOutlet weak var cellDateAdded: UILabel!
@IBOutlet weak var cellDueDate: UILabel!
@IBOutlet weak var cellStatus: UILabel!
func loadCell() {
cellLoanName.text = my_Data.myLoanName
cellMonthlyPayment.text = String(my_Data.myMonthlyPayment)
cellBalance.text = String(my_Data.myBalance)
cellDueDate.text = String(my_Data.myDueDate)
}
}When I push the 'confirm' button, I want data to be passed to a tuple that is outside of a class. I create an instance of the struct that will receive the data.@IBAction func btnConfirm(_ sender: UIBarButtonItem) {
var valueToPass = MyData()
loanData()
containsName()
if txtLoanName.text == "" {
return
}
if doesContainName == false {
txtConfirmMessage.text = "Your New Loan\n'\(loanName)'\nhas been Added to your Loans!"
txtConfirmMessage.textColor = .systemGreen
loanData()
valueToPass.myLoanName = loanName
valueToPass.myDueDate = dueDate
valueToPass.myMonthlyPayment = monthlyPayment
valueToPass.myBalance = balance
}
}Then when I push a different button, the 'myLoans' button, I want the data to load in a table view showing the custom cell data. I created an instance of the custom cell class.class MyLoans: UIViewController, UITableViewDataSource, UITableViewDelegate {
var customCellData = CustomTableViewCell()
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if stringLoansArray == [""] {
let cell = myLoansTable.dequeueReusableCell(withIdentifier: "cell")
cell?.textLabel?.text = stringEmptyArray[indexPath.row]
cell?.textLabel?.font = .systemFont(ofSize: 30)
cell?.textLabel?.textAlignment = .center
cell?.textLabel?.numberOfLines = 2
return cell!
} else {
let cell = myLoansTable.dequeueReusableCell(withIdentifier: "custom cell") as! CustomTableViewCell
myLoan()
customCellData.loadCell()
cell.textLabel?.adjustsFontSizeToFitWidth = true
return cell
}
}When I run the program, it does everything right until I tap the 'My Loans' button. The program crashes and I get an error.func loadCell() {
cellLoanName.text = my_Data.myLoanName Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value
cellMonthlyPayment.text = String(my_Data.myMonthlyPayment)
cellBalance.text = String(my_Data.myBalance)
cellDueDate.textThread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional valueCan I get some help please?
I am trying to fill an array in a different view controller and different class. What I am trying to do is check to see if a string is in an array in a different view controller. If the array does contain the string, then I want to display a message and if the array does not contain the string, then I want to append the string to the array. I actually want to send more data with the string. I am thinking that I need to use an array of tuples. I want a string for the name and a cost and monthly payment of the string. I want all of this information to be attached to the string. I am sending it to a table view in the other view controller. I only want to display the string in the table view. Then when the row of the string is clicked, I want it to take me to a different view controller and display the rest of the information attached to the clicked string in a table view. How would I do that? I also need to save the information so when I go to different table views, the information is still there. Can anyone provide me with examples of what to do?
Post not yet marked as solved
After creating a button in trailingSwipeActionsConfigurationForRowAt indexPath, how do I get the button to perform an action? For instance, if I swipe the row, the buttons created show but I want the row swiped to add a line throw the cell and to add the cell to a different table view.
Post not yet marked as solved
I want to store a received call in my iOS app in a table view. How can I store the data from a received call and display it in a table view using Swift 5 and Xcode 10.3?