Editable table view cell - iphone

I am creating an application. I have to implement a bookmark feature, and adding one should be similar to this:
mmm http://img534.imageshack.us/img534/9859/schermafbeelding2010040a.png
I want editable UITableViewCells for text input. I was wondering if there is an easier way then embedding a UITextField into a UITableViewCell. And if not, can someone explain how I can use the UITextField inside it? Thanks

There isn't an easier way, you will have to subclass UITableViewCell and add in the UITextField. Here is a tutorial for using a UITextView should be about the same as a UITextField.

You can just add a textfield to the contentView of your cell, and an (X) button to the accessoryView of your cell. You could do that in a UITableView subclass which would let you add keep track of your added elements with instance variables or properties.
I found this helpful: Cocoa With Love: Easy custom UITableView drawing
Like this:
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:#"myEditableCellId"];
label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, w, h)];
[cell.contentView addSubview:label];

You can use https://github.com/escoz/QuickDialog for simple cases like that. But you probably need to write your own custom cell if it's more complex.

Related

How to add marquee effect on CustomTableViewCell's UILabel?

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.

Custom UITableViewCell SubView Initialisation?

Rather than for example doing this:
UILabel *lbl = [[UILabel alloc] init];
In the cellForRowAtIndexPath which I have discovered it VERY slow and can cause scrolling on your table view to stutter, where would I initialise my subviews such as labels?
I believe it's better to do that in a subclass of UITableViewCell. By doing so, it will be recycled with the cell.
Besides, it could be useful to set UITableViewCell and, as much as possible, its subviews' opaque to YES.
Check this two posts for more information: 1, 2

how to disable the table cell in my tableview?

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;

How to nest a UITextField within a UITableViewCell?

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.

Can't get label to show over background of grouped UITableView

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.