I have to create the custom TableView with the picker control in multiple rows,can anyone help me on this?
You can add the UIPickerView as a subView of UITableViewCell.
[cell.contentView addSubView:pickerView];
Don't forget to return the appropriate height from heightForRowAtIndexPath: method.
if (cellContainsPickerView) return 200.0; // The height of the picker view
Related
I use this ENSwiftSideMenu
it's just a tableView written programmatically,
I want to add a custom view above UITableView in this side menu,
this view contain an Image and text label, like this
How I can do that? and this view's outlet where should I write it? because I just have a tableview class
Inside your viewController where you are creating tableView, Just set your custom view as tableHeaderView in your viewDidLoad.
let headerView = CustomHeaderView()
self.tableView.tableHeaderView = headerView
Edit: Follow this steps to set custom tableHeaderView.
1 ) Create UIView with xib and add Image and Label or other thing that you want inside the UIView.
2 ) Initialize its object in your viewController where you have added tableView.
let view = CustomHederView()
view.imageView.image = image //Set image that you want
view.lblName.text = Name // Set Name
3 ) Set this custom view as tableHeaderView
self.tableView.tableHeaderView = view
Im trying to add views inside custom UITableViewCells. I tried using the [cell.contentView addSubview] method but the views dont appear. What is it I have to do. Thanks
if you are using custom cell then go to your custom cell class and ...
UIView *contentView;
contentView =[[UIView alloc]init];
then set frames of your view...
finally
[self.contentView addSubview:contentView];
In my UITableView, I have a tableHeaderView that should resize itself according to the content. The resizing works fine, however, the tableHeaderView obscures the first couple of cells. Apparantly changing the frame of the tableHeaderView doesn't reorganize the rest of the view.
I've already tried calling [self.tableView layoutSubViews] and [self.tableView setNeedsLayout], but those don't help either. Also tried giving the tableHeaderView from the Interface Builder an outlet to change the frame on that, but that doesn't reorganize the tableView either.
How can I change the size of the tableHeaderView, without hiding any cells, reorganizing the rest of the tableView?
Try setting the tableHeaderView property of the UITableView after you resized your content.
[self.tableView setTableHeaderView:self.myResizedTableHeaderView];
Solved the problem for me. Hope it helps.
I don't know how you created you UITableView, but I tried to create one with a tableHeaderView like you and it's resizing.
I created a class inheriting from UITableViewController
#interface MyTableViewController : UITableViewController {
}
#end
and for the implementation, in the viewDidLoad, I added:
UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];
[header setBackgroundColor:[UIColor redColor]];
self.tableView.tableHeaderView = header;
I have a UITableViewController that is the detail view for another UITableViewController.
On this table is a cell labeled "Date". Using Apple's "DateCell" example (http://developer.apple.com/library/ios/#samplecode/DateCell/Introduction/Intro.html), I have tried to add a UIDatePicker when you touch the cell.
I have wired up everything exactly the way the example does. The only thing I've changed is that I fenced the didSelectRowAtIndexPath code in this:
if(indexPath.section == 1 && indexPath.row == 0)
{
//Date picker stuff
}
This is to ensure it only runs when the right cell is pressed.
For the life of me, I can't get it to work. Clicking it does nothing but turn it blue (selected). Clicking it repeatedly does nothing.
If I scroll to the bottom of the UITableView, clicking it animates up a white rectangle. Clicking repeatedly eventually covers the whole table view.
It doesn't make a lot of sense to me. Please..how can I do this?
If you want more code, I can provide it, but it's virtually identical to the DateCell code. I copied/pasted for the most part.
Thanks in advance,
Clif
Make sure you have a picker object in IB if that's what you are using, then create an IBOutlet reference and connect it to the IB object. I set my pickerView to hidden in IB and make it visible when required. Otherwise you can simply instantiate one as needed.
In your didSelectRowAtIndexPath, you can try the code below and see what happens.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (**your cell/section selection logic here**) {
[self.view endEditing:YES]; // resign firstResponder if you have any text fields so the keyboard doesn't get in the way
[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES]; // Scroll your row to the top so the user can actually see the row when interacting with the pickerView
// Pickerview setup
[self.typePicker setCenter:CGPointMake(150, 500)]; // place the pickerView outside the screen boundaries
[self.typePicker setHidden:NO]; // set it to visible and then animate it to slide up
[UIView beginAnimations:#"slideIn" context:nil];
[self.typePicker setCenter:CGPointMake(150, 250)];
[UIView commitAnimations];
}
}
After that you need to implement your pickerView:didSelectRow: method if you want to update the label of your cell as the picker view selection changes...
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
// Your code to get the current table view cell and update it with the data from your pickerView
}
Make sure your viewController is declared as delegate for the tableView <UITableViewDelegate> as well as for the pickerView `'
This should give you a good head start. Let me know if you have any questions etc.
Cheers,
Rog
how is it possible to add an image to be set inside an uiscrollview using just interface builder and no code. i tried simply adding an image into the scrollview and it didnt work. i know this is a really simple answer however i didnt find any IB related help on achieving this
You can add the image to the scroll view in Interface Builder, but in order for it to scroll (even if the image is larger than the scroll view) you need to manually set the scroll view's contentSize property in code, as I am not aware of any way to set this property in Interface Builder. In your view controller's viewDidLoad method, you can add something like:
scrollView.contentSize = imageView.frame.size;
Only one line of code, shouldn't be too much trouble.
Alternatively as other people have suggested you can create a custom subclass of UIScrollView. Then overided initWithCoder:
- (id)initWithCoder:(NSCoder *)coder
{
self = [super initWithCoder:coder];
if (self) {
if ([self.subviews count] > 0) {
UIView* subview = [self.subviews objectAtIndex:0];
self.contentSize = subview.frame.size;
self.alwaysBounceHorizontal = NO;
self.alwaysBounceVertical = YES;
self.showsHorizontalScrollIndicator = NO;
self.scrollEnabled = YES;
}
}
return self;
}
Then set the class of your scroll view in IB to your custom subclass. This will mean the content size is set automatically.
This only works if you have one subview in the scroll view. Otherwise add create a new 'container view', put everything in it, then add this as the only subview to the scroll view.