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.
Related
Is it possible to have 3 scroll views lets say the middle is the main where is user find objects inside, then user can drag any item and drop it to the right scroll view or left scroll view so that's object will be removed from the middle and dropped either right or left depends on the uses and suppose the user dropped it to the left thus system should add new object to the left scroll view but when the user remove this object and return back to the main (middle) preferred to dropped and added in the same old index if the object was number 2 then the object will added and dropped at index 2 ..etc.
Could you help on this to make this functionality ?
Let's call the items model1 ... model3;
#property (nonatomic, strong) NSMutableArray *mainArray;
#property (nonatomic, strong) NSMutableArray *leftArray;
#property (nonatomic, strong) NSMutableArray *rightArray;
#property (nonatomic, strong) UIScrollView *mainView;
#property (nonatomic, strong) UIScrollView *leftView;
#property (nonatomic, strong) UIScrollView *rightView;
You need make a model class such as ItemModel inherit UIView or NSObject, in ItemModel.h make some property(what property you need and a property about which UIScrollView contains this model)
First, put all models in the mainView's datasourcemainArray, display models in your self.view and call self.view bringSubviewToFront: and give all models a UIPanGestureRecognizer and a method to respond to UIPanGestureRecognizer so you can drag them.
This is the most important part:
Because you want all models to be contained by three UIViews, you must calculate the models frame between self.view.frame and the three UIView frames relationship. In fact, all modelViews is contained by self.view, but when visually displayed, all modelViews is contained within UIScrollViews.
Second, you already have the frame of three UIView, when you drag model, you can get CGPoint about the location of the drag, then call the method CGRectContainsPoint(CGRect rect, CGPoint point), so you can get any view that contains the point you drag.
For exexample, you drag model1 from mainView to leftView, you can get a YES from CGRectContainsPoint(leftview.frame, point), then remove the model1 from mainArray and put model1 in leftArray, meanwhile you need to re-layout the three UIViews.
here is my share URL for the gif:https://pan.baidu.com/s/1slFBva9
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 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];
I have got similar issue with UITableView with a UISearchBar using storyborad as the
tableViews.tableHeaderView. [self.tableView setContentOffset:CGPointMake(0,40)];
worked for me too. But the problem is,I don't want UISearchBar to scroll along with tableview as in Note.app. Can anyone suggest me how to proceed with this?
Don't use a header view. Instead, add the search bar as a subview as the table view superview so it's a sibling.
If you're using UITableViewController, change to use UIViewController instead. The only things you need to do are:
Change the superclass
Add the delegate and datasource protocol definitions to the #interface
Change the XIB so the table view is a subview of a normal view
Add a property #property (weak, nonatomic) IBOutlet UITableView *tableView and connect it in the XIB
I have a custom static UITableViewCell that I want to look exactly the same as a right detail cell (UILabel on the left, UILabel on the right), except I want the right UILabel to be an editable UITextField. Since I want to use this cell in multiple view controllers in my storyboard, I decided the best option would be to create a MyEditableTableViewCell.xib file, along with corresponding *.h,m files. I have two public properties in MyEditableTableViewCell.h:
#property (weak, nonatomic) IBOutlet UILabel *textLabel;
#property (weak, nonatomic) IBOutlet UITextField *detailTextField;
These IBOutlets are connected to the UILabel and UITextField in the .xib file. In my storyboard, where I have a custom UITableViewController subclass, I change the class of the necessary UITableViewCell to MyEditableTableViewCell. I have a property in my view controller that is:
#property (weak, nonatomic) IBOutlet MyEditableTableViewCell *myCell;
However, when I run the app, the cell appears as simply a blank cell. Running some checks on it, I see that [myCell isKindOfClass:[MyEditableTableViewCell class]] returns true. However, the UITextField never seems to get instantiated. When I try to alter myCell.detailTextField.text, nothing happens, and myCell.detailTextField appears to be nil.
Any help would be appreciated!
How are you creating instances of MyEditableTableViewCell? My guess is you're doing [[MyEditableTableViewCell alloc] init] instead of loading them from the nib.
You don't need that property in your view controller. You need to register your cell nib with the table view using -[UITableView registerNib:forCellReuseIdentifier:]. Do that in your viewDidLoad. Then, when you send dequeueReusableCellWithIdentifier: to the table view, it will instantiate the nib, creating a MyEditableTableViewCell, and return it to you.
UPDATE
If you're laying out static cells in a storyboard, using a xib to lay out a cell is somewhat difficult. The simplest thing to do is simply lay out the cell's subviews in the storyboard. You can copy and paste the subviews to each cell if you have a few of the same type.
If you really want to use a xib, the easiest way is to structure your cell's view hierarchy like this:
MyEditableTableViewCell (in storyboard)
|
+- cell's content view (created automatically by UIKit)
|
+- UIView (top-level view of the xib)
|
+- UILabel (textLabel)
|
+- UITextField (detailTextField)
So you set the cell class in the storyboard to MyEditableTableViewCell. Then you create your xib. You set your xib File's Owner class to MyEditableTableViewCell. The xib does not contain a MyEditableTableViewCell. The top-level view of the xib is just a plain UIView, containing the subviews (the label and the text field).
In -[MyEditableTableViewCell initWithCoder:], after doing self = [super initWithCoder:aDecoder], instantiate the xib, passing self (the cell) as the xib file's owner. The cell can have outlets connected to the label and the text field in the xib.
After instantiating the xib, add the top-level view from the xib as a subview of self.contentView. If you're using auto layout, create constraints betwixt the top-level view and the content view. Otherwise, set the top-level view's frame to the content view's bounds and set the autoresizing mask to UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight.
Although a static table view will not fetch your cell from the nib, it will still call cellForRowAtIndexPath. There you can dequeue and return your fully unarchived custom cell. Properties on the custom cell that were set in IB, can be fetched by calling super on cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// get an empty cell with properties retained from IB
UITableViewCell *sup = [super tableView:tableView cellForRowAtIndexPath:indexPath];
if ([sup isKindOfClass:[MyCustomCell class]]) {
// fetch a fully unarchived cell
MyCustomCell *cell = [self.tableView dequeueReusableCellWithIdentifier:#"foo" forIndexPath:indexPath];
// copy properties over...
[cell copyPropertiesFromCell:(MyCustomCell *)sup];
return cell;
}
return sup;
}
Depending on the situation, this might actually be easier than to mess with IB objects.