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.
Related
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
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.
I created an xcode project with the master detail template. I want to customize the cell to put my data into 2 separate labels. I tried customizing the cell in the storyboard editor, but it seems like all of the stuff on the cell is locked in place. I am fine either creating the custom cell programmatically or in the storyboard editor. I know I could just set the text on the default textLabel to blank and then create the other labels programmatically, but that doesn't seem very need to just have a random empty textLabel in the middle of every cell. So I am wondering if there is a way to edit the cell in storyboard editor, delete the default textLabel, or resize and reposition the textLabel to where I need it to go.
Any help is greatly appreciated.
Thanks in advance.
That's standard practice. Just ignore the built in textLabel and be done with it. By default the label is blank anyway. It's set in code.
To access new labels and such, create a new custom class for the custom cell (File|New|File...|Objective-C Class in XCode), give it a name and for the subclass choose UITableViewCell. Finally, on the Identity Inspector for the custom cell in Interface Builder, choose that new class for the Custom Class.
Now, from the Assistant Editor in XCode, you can CTRL-drag new labels and such to the .h file of the new custom cell class to create IBOutlet properties.
Be sure to set the cell Identifier on the Attributes Inspector tab for the cell and reference that in your code, especially in cellForRowAtIndexPath.
Import the custom cell class's .h file in the view controller's .h file, then cast the cell to your custom cell class in cellForRowAtIndexPath to access the new properties or change the definition UITableViewCell *cell = to your new class like MyTableViewCell *cell =.
By default, the Style of the table cell is "Basic" in Master-Detail projects. Select the Table View Cell and open the Attributes Inspector. Change the Style from Basic to Custom.
Doing this removes the default label and allows you to add new controls.
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.
I have added prototype cell in one of the controllers that is part of the storyboard I'm designing. It has various labels, buttons, bells and whistles.
But how do I know create outlets to that cell's elements? If I click the assistant in Xcode, it will show me the dummy source of my inherited UITableViewController and not of the "DetailsCell" which inherits from UITableViewCell and is specified in the custom class input field in IB.
I could of course use ViewWithTag() but I'd rather have something strong typed.
With any object you can create with IB, you can assign it to a different class (one that you wrote). This is not different for cells. In the same way you can make IB instantiate MyFooView instead of UIView (MyFooView being derived from UIView), you can do the same for the cells.
Click your cell, click the 3rd icon on the shelf to the right. You will see a section called "Custom Class" and a text field called Class. Select the new class you've just created that is derived from UITableViewCell (let's call it MyCell). You can add IBOutlets to the MyCell class.
You first need to create a class DetailedCell and add IBOutlets to that class.
Then in the Storyboard/IB, assign that class to the prototype cell and those outlets will be available to fill.