2

I've been trying to do this for a good few days now but to no avail. I've kind of got myself into a muddle too. Now I'm really confused how I should approach this. Where to start in a new .h and .m file. :/

My goal is to put a UITextField in a few UITableViewCell. Just like this:

enter image description here

and this:

enter image description here

Can somebody assist me with some kind of tutorial?

Thanks.

3 Answers 3

1
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:kCellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
                                       reuseIdentifier:kCellIdentifier] autorelease];
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
        if (indexPath.row== 0) {
            UITextField *TextField = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 185, 30)];
            TextField.adjustsFontSizeToFitWidth = YES;
            TextField.textColor = [UIColor blackColor];
                TextField.placeholder = @"mathie";
                [cell addSubview:TextField];
            }
return cell;
}
1
  • shouldn't you adjust the height of the text field so that it fills the cell height to make it easy to select? Jul 29, 2011 at 18:37
1

You could just create a new NIB consisting of a UITableViewCell. Once you have that you can add any other UI elements to in, in your case the UITextField.

In your code you can call your custom UITableViewCell like this:

UITableViewCell *cell = [saleItemsTableView dequeueReusableCellWithIdentifier:cellIndedifier];

if (cell == nil)
{
    [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
    cell = saleItemsCell;
}

Hope this helps.

Regards

2
  • Hmm... Would it be easier to programmatically draw it? I've read a few forums that says loading nib files would slow the app down? Do you know how to draw them instead of touching the nib? Thanks.
    – K.Honda
    Jun 21, 2011 at 9:32
  • Not really, if all you want to do is load a few simple UITextField objects I can't really see how that will have any major performance impact.
    – RynoB
    Jun 21, 2011 at 9:38
0

Check below apple default tutorial.

It will be helpful to you.

https://developer.apple.com/library/prerelease/ios/#samplecode/AdvancedTableViewCells/Introduction/Intro.html#//apple_ref/doc/uid/DTS40009111

It's about "AdvancedTableViewCells".

It will ask to login to your apple account. So just login, and download example.

2
  • Sorry, that tutorial doesn't demonstrate the UITextField in the UITableViewCell. Do you know any others that are similar to doing the Login function shown by the pictures I posted? Thanks.
    – K.Honda
    Jun 21, 2011 at 9:30
  • Ohh! ok. Currently, I don't have. If available then will let u know.
    – Nishant B
    Jun 21, 2011 at 9:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.