I am trying to get a label to show over part of the grey-space in a grouped UITableView, but it only appears if the label is in a cell. I have tried adding the label as a subview of both the ViewController and the tableView and bringing it to front, but in either case it only shows over the white-space of a cell, not over the grey-space of the background. I know that I am a complete noob at Obj-C and iPhone dev and that this is a really stupid question, but I would really appreciate any help.
My code:
CGRect cgRct = CGRectMake(180, 20, 100, 50);
label = [[UILabel alloc] initWithFrame:cgRct];
label.text = #"Editting On";
label.textColor = [UIColor redColor];
label.hidden = TRUE;
//Display label
[tableView addSubview:label];
[tableView bringSubviewToFront:label];
There is probably a way to get this to work, but I'm betting that what you're trying to do is much simpler than you're making it. So, maybe explain what you want to do.
The first thing I see is you've set the hidden property to TRUE (you should be using YES, instead of TRUE by the way). If the label is hidden, you won't be able to see it, so either remove that line or change its parameter to NO.
Next, I should point out that you can add custom views for the table header and footer. You can even use custom views for section headers and footers. If what you want is a custom cell, then you'll want to either code that by hand or create a custom cell view in Interface Builder and then load it dynamically.
If what you are wanting, however, is to overlay the entire view with another view, then it will work to add the view to the top level controller's view--which is to say if you have a navigation based app, for example, you can access the navigation controller and add your view as a subview.
[[[self navigationController] view] addSubview:label];
HTH.
Related
I have customtableview cell. In viewController, I want to add marquee effect in UIlabel placed in custom cell. marquee working perfectly, but I am not able set in custom cell label. cell.uiprodname.text is custom cell's label. My code is
MarqueeLabel *Label2 = [[MarqueeLabel alloc] initWithFrame:CGRectMake(10, 100, self.view.frame.size.width-20, 20) rate:100.0f andFadeLength:10.0f]; <= here i want to set cell.uiprodname.text instead of cgrect.
Label2.font = [UIFont fontWithName:#"Helvetica-Bold" size:15.000];
Label2.text = cell.uiprodname.text;
[self.view addSubview:Label2];
I want marquee effect inside each custom cell.
You need to checkout this code over github
You are also required to check the issues coming with MarqueeLabel here
I personaly did use MarqueeLabel but it causes the app to stuck anytime at any place. So make sure you download the upgradedversion.
Just to be clear, follow the following tutorial to create a custom UITableView.
Custom Tableview
In that tutorial, when you drag and drop a UILabel, change the class in its inspector to the required one (I'm guessing MarqueeLabel). Then drag it into the .h file and continue.
In my Universal IOS4 app, I have a UITableview in my xib and I control it with my UITableViewController. As you know tableview by default covers all the area in window left from the navigation bar on top and the toolbar at the bottom.
What I want is to add another UIComponent(probably a big UILabel) just under the navigation bar and place the scrollable tableview just under that UILabel, so UIlabel is not scrollable but only the table is
How can I do and control that?
Thanks
Never mind: I think this will scroll with the table.
You can set the section header to the view below. This may work if you only have one section. Best solution would be to change to a UIViewController.
Programmatically add a header to the table
UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(0,0,320,30)] autorelease];
UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(0,0,50,30)] autorelease];
label.text = "Hello";
[view addSubview:label];
self.tableView.tableHeaderView = view;
I would suggest not to go with using UITableViewCOntroller at all. If you use UITableVIewCOntroller to ease the way you use Delegates and Data Sources, then you will have to face this kind of Customization problems.
You will have below problems if you UITableViewController:
can not set the background to a custom UIImage. You can only set the UITableView’s BG property. If you use a Custom VC and add a UITableView to it. you can entirely customize what to keep on top of the View, widtt and height of your table view.
You can not have a static Header view in your View at all. Because if you use UITableVC, you can only have the default header that you can create using Table View's data source methods. But if you use a customized VC and add a TableView to it, you can add your own customized header or controls as a header.
only advantage you will have if you use a UITableViewController is that if you have UITextFields in your Table View, UITableViewCOntroller will automatically scroll the hidden text field to above the Keypad if you start editing one.
I would not suggest you to add anything to UIWIndow, as only the first added view to window will get the rotation events
http://developer.apple.com/library/ios/#qa/qa1688/_index.html
One simple idea is to have another UIViewController (let's call this a_viewController) and set the tableview (let's call it a_tableView) and the label (samewise, a_label) as its subviews.
[a_viewController.view addSubview:a_tableView]
[a_viewController.view addSubview:a_label];
TableView header may not work in case you want the label to stay as you scroll.
But if you have only one section in your tableview, section header may become a handy option.
Can i make a table's tableHeaderView position fixed as I scroll?
One of the way is you can add on UIWindow. But make sure you handle it properly while navigating views... Following is the way...
UIWindow* window = [UIApplication sharedApplication].keyWindow;
if (!window)
window = [[UIApplication sharedApplication].windows objectAtIndex:0];
[[[window subviews] objectAtIndex:0] addSubview:myView];
Create your UILabel instance (myView) and add it as subview in UIWindow...
In my app I need to do something like this:
First of all I have a tableview that contains 3 section (2 of them with 3 rows). Below this tableView I have to put a label,and below the label a textfield.
I tried to do this on xib file. I put a scrollView, and on this scrollView I put the tableview,the label and textfield. The problem is the view is not enough for all of them.
First of all,I want to see the tableview on screen and after I scroll the screen to see the label and textfield . I don't know how can I explain this...I mean that when app starts to see only the tableview on screen and after scroll to appear the label and textfield. Is it possible what I'm trying to do?
You have added those views (Tableview, label, textfield) in the nib file right?
Link all them to different variable to refer them.
set the frames through coding. like
tblView.frame = CGRectMake(0, 0, 320, 416);
label.frame = CGRectMake(60, 420, 200, 50);
textField.frame = CGRectMake(40, 480, 240, 31);
finally set
tblView.scrollEnabled = NO;
scrollView.contentSize = CGSizeMake(320,520);
UITableView is scrollable and i don't think that you need to take a UIScrollView for your task.You can add a label as a cell row textlable and a UITextField as an AccessoryType in your TableView.
Hope it would help.
There can be two approaches for your problem.
First approach :
No need of taking a UIScrollView. You can shorten your UITableView height and fit all three views on your screen.
Second approach :
Increase the content size of UIScrollView (increase Y parameter).
Yes it is 100% possible. You need to go through two types of tutorials and then you can integrate them for your own use.
You need to learn how to build customized table cell.
You need to learn to create table with multiple headers.
You don't need to use scrollview at all as it is already there in tableview. Or in simple words tableview is build on scrollview. So scrolling property is inherited.
Merge both techniques and you will have you custom tableview. It would not be easy but definitely you can achieve it.
i have a my requirement disable the table cell.i have controls on that cell like(textFeild,imageview,button).when i access one control it prefprms another action so plz help me . thanks in advance.
It is not clear what you want exactly. If you just want to disable the cell i think you mean this
cell.userInteractionEnabled = NO;
But what do you mean by when i access one control it performs another action ?
I would suggest using custom UITableViewCells. Put all your controls on custom cells, that way all the events pertaining to that controls would be called in the actions in your custom cell class. In the tableView class you just don't have to give any implementation for didSelectRowAtIndexPath. That way your controls on the cells would be clickable.
It could also apply a color effect:
UIView *lab = [[UIView alloc] initWithFrame:cell.frame];
[lab setBackgroundColor:[UIColor lightGrayColor]];
cell.backgroundView = lab;
I'm just starting out working on my first iOS app. How do you create a UITableViewCell that contains a UITextField that looks like the Title and Location fields when adding an event within the Calendar application? Are there any handy third-party components for doing this?
I can see that the table view has two grouped items and that the text fields have some placeholder text, it's more about how to go about making the text fields take up 100% of their parent table view cells.
Thanks in advance for any help.
You need to add the UITextView as a subview of the UITableViewCell. In the cellForRowAtIndexPath: method do the following:
Create a UITextView as you normally would:
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0,0,300,40)];
NB: the numbers are the x, y, width, height. Modify these to fit your own app.
Add it as a subview of the cell:
[cell addSubview:textView];
If you only want specific cells to have the textview you will need to do something like
//Use the if statement to specify which row(s) you want the UITextView to appear in
if (indexPath.row == 1) {
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0,0,300,40)];
[cell addSubview:textView];
}
The Table View Programming Guide for iOS has a section called A Closer Look at Table-View Cells. It describes two techniques for customizing a table-view cell: with code and using a pre-built nib. I think it has a lot of information you will be interested in.