UITextField in UITableViewController - ios

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

Related

Create properties for Static UITableViewCell Subclass

I decided today that using static tableViews would suit my app better than dynamic ones.
Each cell has a label, and a UITextField
I subclassed one of the static cells and then tried to create IBOutlets for the label and textField... only it wouldn't work. Zero IBOutlet functionality when it comes static cells apparently and their subclass
I can however drag in IBOutlets to the UITableViewController these cells are apart of
So, essentially I would have a UITableViewController with outlets for each cell, each cells textField, each cells label, and potentially any other properties I want to add to the cell
I didn't want that much annoying code so I tried using dynamics
I was able to create IBOutlets for each object the way you can normally expect
I again decided against dynamics UITableViewCells, and switched back to static...
ONLY the static cells now have IBOutlets connected to them (they didn't disappear or throw errors when i returned to static UITableView)
I can access the cells properties by using cell.textField which is a lot better than a billion IBOutlets for each object on the cell
My question is... Why can't I create IBOutlets on the subclass of Static TableViewCells
Is the way I did it the only way, or is there a better way? I would hate to keep switching back and forth, but it allows me to get rid of dozens of lines of code I'll do it
When you create IBOulet for a UITableViewCell and you try to connect them on your StoryBoard, go to the left bar (where the objects of your view controller are) and press Ctrl + Click over your custom cell. Then the IBOutlet object will appear in a popup and you will be able to link them.

UICollectionview with IBOutlet-UIButtons not working

I have a two-days-brain-breaking-question to all of you:
I integrated a menu in my application by using a UICollectionView (one line, horizontal scrolling, fixed number of 9 items). Every cell has an own tag and uses an own prototype cell with own identifier. During the cellForItemAtIndexPath I assign a prototype cell to every cell (the prototype cell contains the specific UIButton in the storyboard). If you click a cell (respective the UIButton) a popover should open (this is working quite well, because the popover is anchored to the collection view not to the cell - otherwise Xcode will give an error, because of an outlet bind to repeating content.). Now to the questions:
Dependently from the chosen value in the popover, the name (titleLable.text) of the button should change. I think, an IBOutlet is needed, but not usable, because of the possible (but not happened) multiple (re)use of the cell.
Some other action in the APP could happened randomly, that changes the label of the button. Therefore an IBOutlet is needed too, I think.
I tried to give the prototypes a specific tag, but this (in my opinion) could not be used, because I cannot assign the tags to an UIButton, during loading, because not all of the cells are visible and therefore not reachable in viedDidAppear...
Any help is appreciated. This is a new try for an old problem and the collectionView till yesterday looked quite promising. Any ideas to help? Thanks a lot. I canĀ“t give code, because 90% of the work are done in IB.
you can use NSNotificationCenter to send message from your UIPopoverController to a UICollectionViewCell.
Send and receive messages through NSNotificationCenter in Objective-C?
Just subclass UICollectionViewCell to MyCollectionViewCell and use your subclass in your UICollectionView.
At the -(void)initWithFrame:(CGRect)frame method of MyCollectionViewCell you should subscribe as an observer to NSNotificationCenter, and unsubscribe in dealloc.
Than all your cells may receive notification and react to it.
This is not an optimal way of receiving callbacks, but maybe the simplest.

change the position of textfield inside an expandable uitableview cell in iOS

Hi, I am new to iOS and i am trying to have two text fields inside a custom table view cell and the cells are dynamic, so I will be having two text fields in each cell and when a cell is selected the cell will expand
How can I reposition the text field when the cell expands? One text field should be on the top and the other one on the bottom inside the tableview cell.
How can i access the uitext field delegate inside uitable view delegate
i.e.:
textFieldShouldBeginEditing inside tableView:didDeselectRowAtIndexPath:indexPath
Thanks in advance
I would suggest having two different custom UITableViewCells - one for viewing and one for editing. When didSelectRowAtIndexPath is called, replace the selected cell with the second custom cell designed for editing. When the user is finished, replace it again with the original custom cell type.
For your second question about accessing subviews of the UITableViewCell, you have several options. I'm going to assume you're using storyboards.
If you created a custom class for your UITableViewCells, you can add the UITextView as a class property and connect it as a outlet from your storyboard to your class by making it an IBOutlet. That way you can access it via self.nameOfTextView.
If you don't want to create a custom class for your UITableViewCells, you can assign the subviews tags and access them via (UITextView *)[cell.contentView viewWithTag:1]. This second option can also be used if you aren't using storyboards.

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