Programmatically created UITextField hides other controls - iphone

I've requirement to create dynamically some controllers. In the image provided here I've programmatically added an UITextField (name), which hides UITableView.
UITableView is hidden by default. When user touches the UIButton above it, UITableVIew gets appear.
My question when UITableView gets appear, how can I make UITableView top of all other controls?

you will have to change the sequence.
Add UItextfield first
[self.view addSubview:yourTextField];
and add tableview and other views after that line of code so that they appear above it.
[self.view addSubview:yourTableView];

Try
[self.view bringSubviewToFront: yourTableView];

I think this will work fine so please implement this one.
UITextField *txtFld = [[UITextField alloc] initWithFrame:CGRectMake(65, 300, 200, 30)];
txtFld.backgroundColor = [UIColor clearColor];
// Border Style None
[txtFld setBorderStyle:UITextBorderStyleNone];
[txtFld setPlaceholder:#"Name"];
[self.view addSubview:txtFld];

Related

ios - how to add view dynamically

i am new to ios develepoment
i have created a function name list which is called after a button is clicked it should load a view dynamically this is my code
-(IBAction)list:(id)sender{
UIView *listView=[[UIView alloc]initWithFrame:CGRectMake(0,0,1024,786)];
[self.view addSubview:listView];
}
but it does not create any view but it calls this function
can anyone help me
Thanks.
Arun
Try
listView.backgroundColor = [UIColor redColor];
If you don't see anything on self.view, check by
for(UIView *aView in self.view.subviews){
NSLog("%#\n",aView);
}
There is not any problem with your code, It will work fine.
You just check two thing
Make some background color in your view
[listView setBackgroundColor: [UIColor redColor]];
You have proper IBAction connection on your button
If you getting redColor on your View mean listView is adding over your view.
EDIT
If your want to add UILabel and UIButton in your view then
[listView addSubview:yourLabel];
[listView addSubview:yourButton];
Make property of listView in .h
-(IBAction)list:(id)sender{
self. listView = [[UIView alloc] initWithFrame:CGRectMake(0,0,1024,786)];
[self. listView setHidden:NO];
[self. listView setBackgroundColor:[UIColor grayColor]];
[self.view addSubview:self.listView];
}
Try out this.
[self. listView setBackgroundColor:[UIColor greenColor]];
your view display with green color..if it is not display check out the connection to the -(IBAction) method...

UIToolbar above custom UIPickerView not receiving touches

I've subclassed UIPickerView to add some a little more functionality(I'm 99% sure it has nothing to do with this question). In drawRect I added a toolbar to make dismissing the toolbar a little easier, the problem is, neither the UIToolbar, or the UIBarButtonItem inside the toolbar receive touches. It's almost as if the view is "invisible" in that the touches are forwarded to the view behind it(a UITableView). I know I could just make a "control" view that holds both the picker an a toolbar. But I just wanted to know if there was any way to do this without creating another view?
Here's my drawRect code:
- (void)drawRect:(CGRect)rect
{
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
pickerToolbar = [[UIToolbar alloc] initWithFrame: CGRectMake(0, 0, self.frame.size.width, 40)];
UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemDone target: self.delegate action: closeAction];
[pickerToolbar setItems: [NSArray arrayWithObject: closeButton]];
[self addSubview: pickerToolbar];
}
}
Here's a photo:
Never, never do this. You are adding a new subview every time the picker is drawn!
If your picker view is the input view of a text field, simply create a toolbar and add it as the input accessory view. It will then appear above the picker for you. This is the standard way to achieve this behaviour.

Show some help text over a UITableView if the UITableView happens to be blank

I've got an app with several UITableViews in it, and if one of them is empty, I'd like to display a bit of help text, floating in front of the UITableView:
"Looks like you haven't created anything for this list yet. Make your first entry by tapping the button above."
How do I present this view, floating in front of the UITableView?
What method of the UITableViewDelegate would be used to present this view?
What would the code look like to present the view?
What method of the UITableViewDelegate would be used to hide this view once the user adds content?
Here's a quick mockup:
declare in .h file
UIView *root;
in .m file
import QuartzCore/QuartzCore.h
- (void)viewDidLoad
{
[super viewDidLoad];
root = [[UIView alloc] initWithFrame:CGRectMake(60, 50, 220, 250)];
root.backgroundColor=[UIColor grayColor];
root.layer.cornerRadius=10;
UILabel *label=[[UILabel alloc] initWithFrame:CGRectMake(10, 100, 200, 50)];
label.backgroundColor=[UIColor clearColor];
label.numberOfLines=3;
label.font=[UIFont fontWithName:#"Arial" size:14];
label.lineBreakMode=UILineBreakModeTailTruncation;
label.textColor=[UIColor whiteColor];
label.text=#"Make your first entry by tapping the button at the top of the screen";
[root addSubview:label];
[self.view addSubview:root];
}
inside your button Event method
[root removeFromSuperview];
in viewDidLoad/Appear,
create a view and add it as subview [self.view addSubview:infoView] . on click event of + button remove it from superview [infoView removeFromSuperView]
I would create/remove the view in numberOfRowsInSection (if it is 0 then show the view) or whatever it is called. As for the view itself, have a UILabel in a custom view. To add the rounded corners etc you can access the view's layer, which is a CALayer. Oh and make sure that you have an ivar for the view so you can remove it easily and check if it is visible. And make sure you always reload the table view when you show your view, as otherwise numberOfRowsInSection will not be called.

added button to uitableviewcell not responding

I have created a custom tableviewcell through interface builder with a label and a button. In the .h and .m file I have made outlets and actions for the button which I have connected.
This cell is added to a tableview controlled by a uiviewcontroller class. However my problem is that when I tap the button, the button is not activated, however I am pushed on to the detailed view belonging to the cell. It seems like the button is behind the cell.
Any suggestions for what I have forgotten or should change?
I have created a button programatically and added as subview to the cell instead and this works, however this gives me another problem as the button is added everytime a cell is loaded.
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setFrame:CGRectMake(200.0f, 5.0f, 100.0f, 40.0f)];
//Set image
UIImage *img = [UIImage imageNamed:#"myPackage.png"];
[button setImage:img forState:UIControlStateNormal];
[img release];
[button addTarget:self action:#selector(myPackagePushed:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:button];
I would really like to use the interface builder approach - any suggestions?
Regards
try
[cell.contentView addSubview:button];
also
UIImage *img = [UIImage imageNamed:#"myPackage.png"]; here you are not allocating memory so no need for
[img release]; because there is a possibility of crash
The button should fire the IBAction method that you have set in IB. Have you checked by inserting an NSLog or by setting a breakpoint if the method is entered?
Is the button set to be initially activated in IB?
The crux with the IB construction is that the IBOutlet gets its value when the cell is loaded from the xib. The IBOutlet will then be the button in the cell that the tableview happend to load last.
WHen you add the button programatically, you might need to have the previous added button to removeFromSuperview before you add a button again to that cell.
In my case, the problem was that the button was a subview of the background view.
Buttons assigned to the background view apparently can't respond to touches.

Add UISegmentedControl in table cell programmatically with clear background

I have grouped table view. I want to add UISegmentedControl in table cell with clear background so that it will be displayed as FOOTER . How can I do this? I tried using clearColor. But it's not working.
Set the background view with a clear UIView object like so:
UIView *clearView = [[UIView alloc] initWithFrame:CGRectZero];
[clearView setBackgroundColor:[UIColor clearColor]];
[self setBackgroundView:clearView];
[clearView release];
And make sure you set cell selection style to none.
Edit: added some square brackets