PDA

View Full Version : Add Table View Cell when user tap...




Patr1k
Jun 9, 2009, 12:16 PM
Hi all,

I am new here, I have one question:
If I have created table view and on the top I have navigation controller (and here is button for add row). But my class is uiviewcontroller (because I have tab bar too) and I have no class UITableViewController. So, I dont know, how to write code for the add action.
Here is my code:

@interface SettingsController : UIViewController {

NSMutableArray* clickerList;

IBOutlet UITableView *settingsTableView;
UINavigationController *navController;

}

@property (nonatomic,retain) NSMutableArray* clickerList;
@end

@implementation SettingsController

@synthesize clickerList;
- (void)viewDidLoad {
[super viewDidLoad];

self.navigationItem.title = @"Settings";

self.navigationItem.leftBarButtonItem = self.editButtonItem;

UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithTitle:@"Add" style:UIBarButtonItemStyleBordered target:self action:@selector (add];
self.navigationItem.rightBarButtonItem = addButton;
[addButton release];

self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
}

- (IBAction)addid)sender
{
//Some code here
}

And then I have created normal tableView (specified its property and so on)

So, please, anyone know, how to do it?
Thank you a lot of



dejo
Jun 9, 2009, 12:25 PM
Welcome!

First, I'll start by suggesting you enclose code snippets in ...tags, accessible via the # icon in the toolbar. Makes it easier for us to read (and avoid unintentional smiley translation).

Second, how and where are your tableView datasource and delegate set up?

Patr1k
Jun 9, 2009, 12:40 PM
Ok, I think, I have done it

dejo
Jun 9, 2009, 12:47 PM
I'm thinking something along the lines of:
- (IBAction)add:(id)sender
{
SettingsItem *newItem = [[SettingsItem alloc] init];
[clickerList addObject:newItem];
[newItem release];
[settingsTableView reloadData];
}

Patr1k
Jun 9, 2009, 12:51 PM
Oh, Ok, it works. But what to do, if I want add some text to table view?

Thank you

EDIT:
because if I click on the button, new row is added (but with name null), how can i set it?

Thank you

dejo
Jun 9, 2009, 01:03 PM
But what to do, if I want add some text to table view?
Add the text, probably via a method or setter, to the new SettingsItem. I see SettingsItem has clickerName and clickerCounter.

Patr1k
Jun 9, 2009, 01:07 PM
Please, Can you show me some code?
I want only put text to new added row... Thank you...

dejo
Jun 9, 2009, 01:19 PM
Please, Can you show me some code?
You just want me to give you the whole solution? I'm afraid I'm going to expect you to do some of the work yourself.

Patr1k
Jun 9, 2009, 01:32 PM
Ok, Thank you a lot of...

But I have one last question. Do you know, how to make scroll view, if all I have created in IB?

Thank you