Label Text cannot connect IBOutlet in Table View - uitableview

I put one label text in my Table View row. Then Ctrl dragging to the ViewController.swift but error occurs.
How to solve this problem? My Xcode version is 7.3.
enter image description here

You must connect the #IBOutlet into tableView cell class not in the main class. first of all you must make the custom class of tableview cell and assign it on storyboard as suggested in picture and draw #IBOutlet on that custom tableview cell class. Please look the attached image.
Hope it will help you.

Related

Can't add UIButton on custom UITableView without an error

What I'm trying to achieve:
Trying to achieve Google-Now-style like custom TableViewCell with couple of buttons on each card (refer to the provided screenshot here). Using Storyboard.
Problem
I was able to make the card like TableViewCells, but whenever I try to place a UIButton on the card, it will either cause a compiler error or a runtime error.
Current setup
My current storyboard set up looks like this.
Here's my code for the TableView.
What I've tried so far
Drag and dropped the UIButton on top of my card view, which looks like this. Button get buried down somewhere under the tableview? Button does not appear like it should and once I create an outlet to the actual code, compiler error (invalid outlets cannot be connected to repeating content).
Placed the UIButton on top of the Content View. This outputs in same result as above.
Placed the UIButton on top of the View. Now this actually shows the button on the storyboard, however it causes a runtime error and crashes while it tries to display this ViewController.
Here is how it's set up on the Storyboard.
Now, what am I doing wrong here? I've looked at several tutorials on how to place a UIButton on a TableViewCell and it looks dead simple as just placing the UIButton on top of the cell.
EDIT: So I did add a new class for the petListCell and assigned it on identity inspector. I place it on the Card Design View, where the button should belong to, and it is now giving me following compiler error: "/Users/.../Main.storyboard: The feedingHistoryButton outlet from the YourWoofsViewController to the UIButton is invalid. Outlets cannot be connected to repeating content."
You need do like this.
create a subclass of UITableViewCell like PetCell
change the class of the cell in storyboard from UITableViewCell to PetCell
link the button to PetCell like you did with the ViewController
You can change this.
create First a subclass of UITableViewCell like PetCell
And change the class of the cell in storyboard from UITableViewCell to PetCell
link the button to PetCell like you did with the ViewController

UITextField in UITableViewController

I can't find a question like this. I searched all of the Internet but nobody ask this question. Even Apple's tutorials, there is no example. Here is my what I want to do. I want to create an app like Reminders or Wunderlist. I want to emphasize the UITextField of UITableViewCell's first cell as text input.
My first cell is a static cell which is UITextField and the other cell's are the results of UITextField. For example:
Static cell (UITextField)
dynamic cell (Label)
dynamic cell (Label)
...
There is no button for UITextField. I want to get input from keyboard's return like Reminders.app due to I must implement UITextFieldDelegete and equalize in viewDidLoad like textField.delagate = self. The problem starts here. I can connect outlets in UITableViewCell (for UITextField and cells' labels) but in UITableViewCell's instance method, there is no viewDidLoad method and it disallow to use UITextFieldDelagete which can require to get input without using any button. If I use ViewController (not UITableViewController), I can easily connect outlets and use UITextFieldDelegate. How can I solve this problem? Which point I missed?
Please Check Screenshot how to add any Control into UITableViewController
do not forget to change Static cell instead of dynamic prototype in tableView Property.
IBOUTLETs will connects with your ViewController , not with Custom Cell.
How to Set OUTLEts in TableViewController :
ScreenShot
Please feel free to ask

Add objective-c plugin to swift project

I need help with using this customizeable checkbox:
https://github.com/Marxon13/M13Checkbox
I have already linked m13checkbox.h and .m classes and wrote import in bridge-header file, but i don't know how to create checkbox on my tableview and manipulate it.
I need to place checkbox in every cell by my own UITableCell class.
UPD.
I have done with adding checkbox in cell, but now i need to control it in addiction by my data in UITableViewController. I need to set checkbox to checked/unchecked state depending on my dataArray. I also need to set label for every checkbox from dataArray
In your custom UITableViewCell subclass, you should declare a property similar to the following
#IBOutlet weak var checkbox: M13Checkbox!
Then, in the corresponding prototype cell in your Storyboard:
Drag out a UIView from the Object Library.
Change the class of that view to "M13Checkbox" in the Identity Inspector.
Position the checkbox and add any necessary Auto Layout constraints.
In the corresponding table view's data source, make sure that you are dequeuing cells with the correct identifiers.
When that UITableView is on screen, you should see a checkbox in each cell, assuming your tableView(_:numberOfRowsInSection:) method returns an integer greater than zero.

Strange error when adding items to prototype cells in storyboard-IB

I have quite a large project (~20 scenes). One of which is a TableViewController with a custom UITableViewController class. I have given the cell a reuse identifier, and added a label to it. When I try and Ctrl+Drag the label to the UITableViewController header file to create an outlet, I get the following error:
error: Illegal Configuration: Connection "tableInfoView" cannot have a
prototype object as its destination.
What is this? Am I overlooking something obvious? Or do I need to create a custom cell class and drag the outlet to that? If so, how do I then specify the data which is displayed uniquely for each cell from the UITableViewController?
In fact you can't just make an outlet from a dynamic cell prototype in the UITableView delegate view controller.
You'll have to subclass UITableViewCell and then attribute this class to your prototype.
Then you can Ctrl-Drag from the Label to the UITableViewCell subclass header file.
Finaly you can access to this outlet in the delegate code after having imported the UITableViewCell header file in it.
This is documented by Apple there at "The Technique for Dynamic Row Content" section.
or you could give the label a tag (e.g. 100) and use
myLabel = [myTableView viewForTag:100];
to get the label
I had the same error myself. Just to add one more potantial root cause for future readers:
In my case I copied a control (a Button in this case) from one prototype cell to the next and the action still referred to the neighbor cell. My table has several different prototype cells.
The fact, that it acutally was a proper subclass of UITableViewCell which was properly connected to the prototype cell made it difficult to actually see the mistake.
Tag the label and you can reach the label anywhere in the viewcontroller like with viewWithTag from the table view.
UILabel *destinationLabel = (UILabel *)[self.tableView viewWithTag:1];
destinationLabel.text = #"Label Destaination";
I faced the same problem but later it turned out that it was just a silly mistake.
I mistakenly dragged the label from Cell to my controller's #interface
This could be your problem too. just cross check once.
Set the right reuse identifier used in .m file in the Storyboard for the Prototype cell.I had the same situation and this helped me
After doing every thing right if problem still exist then just removed all outlets and rejoin them carefully and it worked very fine for me.

How to display label in UITableView

I created a UIViewController using story board in Xcode 4.2. Then added a UITableView object to it by dragging it on to the view controller. Then dragged a label to one of the cells of this UITableView and made label's text to be MyFirstLabel. Now when I run this in simulator I am not able to see the label. What am I missing ?
You must create properties for UILabel when adding to cell
let's say you have a UILabel declaration like this(and connected to the object you drag on storyboard)
#property(retain, nonatomic) IBOutlet UILabel* yourLabel;
in your .h file and
#synthesize yourLabel;
in your .m file. After initializing the cell(on the cellForRowAtIndexPath delegate method)
add your label to the cell like this [cell.contenView addSubview:yourLabel]; I hope this helps-if not, please give some more details about your problem
You should see the label. Make sure you have static cells for your table view. You do this by selecting the table view and change this in the inspector. Now you can create the exact number of sections and rows, including the content, right in storyboard.
If, however, you want to change the content of the label, you have to create an IBOutlet, still using static cells.
If you want to vary the number of sections and rows you will have to go with dynamic cells. In this case you should see the label if you have the correct Cell Identifier set in storyboard and referenced in your table view datasource method cellForRowAtIndexPath.
EDIT:
As has been pointed out, you cannot use static table views if not embedded in a table view controller (which claims the whole screen). So here is the workaround:
Option 1: you make it into dynamic cells as mentioned above and implement the datasource protocols in your ordinary view controller. You could then insert the label in code.
Option 2: as option 1, but with subclassing UITableViewCell where you can design the cell with a xib and create the necessary outlets.

Resources