Add Table View Cell when user tap...

Discussion in 'iOS Programming' started by Patr1k, Jun 9, 2009.

  1. Patr1k macrumors newbie

    Joined:
    Jun 9, 2009
    #1
    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:mad:"Add" style:UIBarButtonItemStyleBordered target:self action:mad: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
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Welcome!

    First, I'll start by suggesting you enclose code snippets in
    HTML:
    [code]...[/code]
    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?
     
  3. Patr1k thread starter macrumors newbie

    Joined:
    Jun 9, 2009
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    I'm thinking something along the lines of:
    Code:
    - (IBAction)add:(id)sender
    {
            SettingsItem *newItem = [[SettingsItem alloc] init];
    	[clickerList addObject:newItem];
            [newItem release];
            [settingsTableView reloadData];
    }
    
     
  5. Patr1k thread starter macrumors newbie

    Joined:
    Jun 9, 2009
    #5
    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
     
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    Add the text, probably via a method or setter, to the new SettingsItem. I see SettingsItem has clickerName and clickerCounter.
     
  7. Patr1k thread starter macrumors newbie

    Joined:
    Jun 9, 2009
    #7
    Please, Can you show me some code?
    I want only put text to new added row... Thank you...
     
  8. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #8
    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.
     
  9. Patr1k thread starter macrumors newbie

    Joined:
    Jun 9, 2009
    #9
    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
     

Share This Page