how can i add a call button to cells [duplicate] - ios

This question already has answers here:
detecting uibutton pressed in tableview: Swift Best Practices
(12 answers)
Calling a phone number in swift
(25 answers)
Closed 3 years ago.
I'm trying to develop my first app on IOS platform and i want to add a call button to different cells and give each cell a different number to call because I want to programmatically add number to each cell to call ((for example I want cell A to call only the number 123 when I press the call button and I want the Cell B to only call 456 when I press the call button in that cell , I have a service class where my data is stored and I have DeatilCell class to update my cell with different data and another class to pass my data to the cells
I tried to search for some answers on the internet but I couldn't find anything

You need to do 2 things:
Have the specific phone number based on the index of the cell.
Call it.
There are many approaches to get a value based on events inside UITableView or UICollectionView cells, just pick one.

Related

save data in array coming from 2 different uitableviews in ios swift

Recently i am facing an issue in saving data of Uitableview inside Uitableview cell in ios swift
Senario
Questions asked in above pictures is one table view and this table view cell contain 1 label for question text and uitableview that show possible answers provided by admin and user is allowed to select one.i am enable to display data perfectly but facing an issue when trying to save answers of every question in one array.it always store the value of last questions answers.
Why are you using two different UITableView? Any specific reason? You can get data from different resources but there is no need to use two table views.
You should use a section header view to show the questions & sections rows as options(answer option).
You can dynamically add or delete the options(rows) from any section(question). Also, there will not be the above scenario if you implement it using this easy approach.
Let me know in case of any query.

How to write code so multiple UITextField's to appear in one cell on the UITableView

I'm having the user input four pieces of information into four different UITextField's (homeTeam, visitingTeam, homeScore and visitingScore). I am very new to Swift and am trying to figure out how to connect those four UITextFields so they show in the UITableViewCell's. I feel like this should be very easy but I am very new to Swift.
I have attached an image so hopefully it makes it easier to understand. I want the information from these four textFields to be displayed in one cell of the ui table view so it shows the two teams and the score of the game. Does that help?
image
You can attach 4 IBActions to the 4 UITextFields, that update 4 different variables.
In the table, add 4 label outlets (you can make the table static, and force 4 rows if you want).
Then when you segue from one viewController to the other, pass the 4 variables into the new segue controller, and update the outlets to display the appropriate data.

How to have different elements in collection view? [duplicate]

This question already has answers here:
Displaying two different cells in a collection view - Swift 2.0 iOS
(2 answers)
Closed 5 years ago.
so I try to have collection view but been thinking is it possible to have different element in each cell view? For Example: in the first cell I have the whole cell covered by UIImageView while some specific cells only got UITextView.
Here's an example that I'm talking about, Medium iOS App.
Create several prototype cells, each formatted with whichever UI elements you want, and dequeue the appropriate cell for each different type of data you want to display.

Swift 3 Show the 'Copy' popup on UITableViewCells when select cell of table like Contaccts app [duplicate]

This question already has an answer here:
How to show "Copy" menu for a table cell?
(1 answer)
Closed 6 years ago.
How to show popup "copy" when select cell of table ?
You can't do it the normal way with UILabel. If you still want to do it, use UITextField instead and disable editing (It will act as label and allow text selection). If you want to use UILabel anyways, you might want to look into UILongGestureRecognizer and UIPasteBoard. Add gesture to the label and on its delegate method, copy text to paste board.

Accessing information from a cell in a new UItableView (Swift) [duplicate]

This question already has answers here:
Find the indexPath of a button inside UITableViewCell when button pressed?
(6 answers)
Closed 6 years ago.
I have a table view which has cells in it. In each cell there is a button to take you to a new UITableView. I am trying to figure out how to get the index of the cell I clicked the button in from the new UITableView because depending on what cell index I choose it needs to show different items in the new UITableView it takes you to. Any help would be appreciated.
set tag property of the button equal to the indexPath.row in cellForRowAtIndexPath method or in your custom cell class if you are using one.
Hence, when its clicked, you can get the value of indexPath.row from its tag (sender.tag).
Note: Assuming there is only one section in your tableview and you wont be inserting or deleting rows runtime. You will have to reload the table in such scenarios.
The best solution that I personally use is, to pass the cell a model object via property or custom method. And later, use the object to make further decisions.

Resources