I have one question regarding UITableViewCell.
I have base class inheriting from UITableViewCell.
In that class I have this:
#property (strong, nonatomic) IBOutlet UILabel *name;
Then I have several cells inheriting from that base class created using xib files.
Now I am adding new cell but in this case I am doing it programatically. My problem is that when I try to set the text for that new cell like this:
[self.name setText:#"My Label"];
Text is not displayed.
How can I fix this?
Thanks and regards
Related
in my AppleTV app, I have a custom UITableViewCell with UITextField inside.
What I'd like to achieve is to be able to focus this text field to enter text in it.
Unfortunately only the cell itself is focussing, I'm not able to focus the text field.
Thanks
The cell is getting focused because it returns YES from canBecomeFocused. If you want something within the cell to become focused, the cell needs to start returning NO from that method. There are two ways to do that: using the table view delegate method, or by subclassing UITableViewCell.
In your table view's delegate, you can implement the method tableView:canFocusRowAtIndexPath: and return NO for the cells that contain text fields.
Or, in your subclass of UITableViewCell, you could override canBecomeFocused to return NO.
Subclass the UITableViewCell and set the preferredFocusedView of the cell to the UITextField.
#interface TableViewCell : UITableViewCell
#property (nonatomic, weak) IBOutlet UITextField *textField;
#end
#implementation TableViewCell
...
- (UIView*)preferredFocusedView {
return self.textField;
}
I have a custom tableViewCell class that has a UIImageView as an IBOutlet.
#property (nonatomic, weak) IBOutlet UIImageView * waveformImageView;
I also have two view controllers: one with a tableView and one without a tableView.
I need to know the height and width of this UIImageView to send to another class to do a calculation in my NON tableView view controller
I tried doing the following in my header file of my view controller (view controller without a tableView)
#property (nonatomic, strong) OSAudioTableCell * tableCell;
and then accessing the UIImageView property by doing the following in one of my methods:
self.tableCell = [[OSAudioTableCell alloc] init];
[self.waveView setSize:self.tableCell.waveformImageView.bounds.size];
This is all done in my view controller that doesn't contain a tableView. I'm pretty sure I'm doing this wrong since the width and height are coming out as zero. I can get these values fine within my view controller which contains my tableView.
Came up this question and did some quick experiments without no luck.
Basically, I made a simple single view project where the top view controller is a UITableViewController. For simplicity, I set the table view content to be "Static Cells". The table cell was a custom subclass of UITableViewCell, like this
#interface TopTableViewCell : UITableViewCell
#property (strong, nonatomic) IBOutlet UILabel *label;
#property (strong, nonatomic) IBOutlet TableCellBottomView *bottomView;
#end
Both the properties were wired through control dragging. The TableCellBottomView is just a custom subclass of UIView like this
#interface TableCellBottomView : UIView
#end
Now I add a label inside this TableCellBottomView like the following picture showing
Can I wire this bottom label inside to my TableCellBottomView? Control dragging did not work for me here. I certainly could have added it programmatically inside TableCellBottomView.m. But if i could wire it here, it would be quite convenient, since I could also add a lot of other components and arrange them visually. Thanks!
You may set a tag for the label in Xcode and fetch the UILabel based on the tag wherever you need it:
If you use dynamic cells, you can do this in tableView:cellForRowAtIndexPath:. Alternatively wire the cell to a property and then use that property to fetch it:
((UILabel*)[cell viewWithTag:1]).text = #"Some text";
I don't know why Xcode won't allow you to drag from your label to the bottom view .h file, but you can do it another way. Add the IBOutlet property to the .h file, then drag from the littler open circle to the left of the #property to your label in the storyboard, and that should work.
I have created a custom UITableViewCell in Interface Builder and also created a class for it, and loaded it into my ViewController by registering its NIB.
Inside the custom cell I have an UIImageView, a UILabel and two IBOutlets for each of them in my customViewCell.h:
#property (strong, nonatomic) IBOutlet UIImageView *assignmentImageView;
#property (strong, nonatomic) IBOutlet UILabel *testLabel;
Now in the the cellForRowAtIndexPath method, I can write to the label outlet with:
cell.testLabel = #"text"
But I am unable to set the image property of the cell.assignmentImageView to some image I want to load. So the following doesn't do anything:
cell.assignmentImageView.image = [UIImage imageNamed:#"my.png"];
I also noticed that the completion feature of xcode doesn't show assignmentImageView as a property of cell, but it does show testLabel. So that leads me to believe that even though assignmentImageView has been set as an IBOutlet, it is for some reason not considered as such.
I tried also using the tag property of the UIImageView and retrieve a pointer to the UIImage in the cell using the viewWithTag method, but that didn't work either.
I know that if I have only a single UIImage in the cell, I can reference it with cell.imageView, which is strange to me, but I want to be able to have multiple UIImageView in the cell and reference them.
Can anyone explain me how to do this?
Thanks
-Malena
Check of your assignmentImageView outlet is wired with a correct view in XIB.
Check if the image you are trying to set is added to your project.
Set breakpoints or use NSAssert or NSParameterAssert statements to verify that UIImage and the assignmentImageView are not nil.
I have a static table, one cell has multiple views that I would like to add subviews. Each view has a class (MHRotaryKnob) assigned.
What I can't figure out is how to ID each view in the cell so I can addSubView.
I have set up the table within StoryBoard.
Give your Viewcontroller an IBOutlet-Property for a UIView like so:
#property (nonatomic, strong) IBOutlet UIView *myView;
then connect those to your desired view in storyboards.
now you can address this view in code like this:
[self.myView addSubview:subView];
Thats probably easier than messing with ids or tags.
If you have problems, this will help you:
http://klanguedoc.hubpages.com/hub/IOS-5-A-Beginners-Guide-to-Storyboard-Connection
EDIT:
If you want ta add a subview to a MHRotaryKnob, you can just go the other way around:
#property (nonatomic, strong) IBOutlet MHRotaryKnob *myKnob;
and then, assuming that MHRotaryKnob is a direct or indirect subclass of UIView, you can add the subview:
[self.myKnob addSubview:subView];