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
Related
in my ViewController and Main storyboard
I'm trying to load a custom view (LogView) programmatically from .xib.
when the "Next" button is pressed a text supposed to appear in the custom sub view (myView). the "DidReceiveJSON" method suppose to load the custom view.
This is how my LogView looks like and the "Display" method suppose to update the "myLog" UIlabel.
EveryThing was working when "MyLog" view only contained a UIView and a UILabel. but I wanted to add a UIScrollView because the label grows every time "Next" button is pressed.
So now when I press the "Next" button nothing is happening in the simulator.
could you please help me figure out what I'm doing wrong?
sorry for not uploading images, but I'm not allowed to upload any images due to my low rank. I did uploaded links to the images and will gladly add any info if needed
Please check if you have connected outlet of MyLog UILabel with File's Owner in the xib. Check if the label is nil or not.
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
I am getting a story board error that is connection imageInCell cannot have a prototype object as its destination. I am trying to connect an image view to a cell class and I am getting this message. I am trying to use the UICollection View. I have added this code and is getting the error
#property (weak, nonatomic) IBOutlet UIImageView *imageInCell;
For some reason even I delete the code I still have the error remaining. Any help is greatly appreciated.
Assuming that you're attempting to create this property somewhere other than in a subclass of UICollectionViewCell, it makes sense that this would generate an error. At run time, you would have one reference to multiple image views and wouldn't be able to properly configure them.
Instead, create a subclass of UICollectionViewCell and add that property there. Then you can go to interface builder and modify "Custom class" in the Identity Inspector the your new subclass and link the image view in the prototype to your property.
Now, after importing the new cells class replacing the UICollectionViewCell in cellForRowAtIndex, etc.. with your new one, you'll be able to do things like [myCell.imageInCell setImage:someImage];
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.
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.