All
Technology
SEO
Design
Programming
iPhone
Android

TableView giving them names and a function...

    Share on Facebook Create Topic
by Alice
TableView giving them names and a function. I know Apple has there code. Yet I don't want that I want just enough code to give at least one if not more cells a name and have it do something when clicked. I have Apples code I have other code What I am asking is for someone to show me from those or there own this bare minimum thanks.
by Hal3
TableView giving them names and a function. I know Apple has there code. Yet I don't want that I want just enough code to give at least one if not more cells a name and have it do something when clicked. I have Apples code I have other code What I am asking is for someone to show me from those or there own this bare minimum thanks.

You're going to want to use the didSelectRowAtIndexPath: delegate method for the UITableView that will tell you which cell is clicked (section and row). Then it is up to you to decide the action to take.
by IjsKind
can you show me a quick example of code to help me understand show the creation of table and nameing and then function if possibal thanks.
by Johngshin
can you show me a quick example of code to help me understand show the creation of table and nameing and then function if possibal thanks.

Ok - I suggest you get very familiar with these two documents:
1: iPhone Dev Center: UITableViewDataSource Protocol Reference and
2: iPhone Dev Center: UITableViewDelegate Protocol Reference

I don't use Interface Builder, for the most part, so here it is in code.

.h file
@interface yourViewController : UIViewController <UITableViewDelegate>{
    UITableView *theTable;
}
@property (nonatomic, retain) UITableView *theTable; 

.m file
@synthesize theTable;

//Init Code 
-(void) viewDidLoad{
    [self setTheTable:[[UITableView alloc] init]];
    [[self theTable] setDelegate:self];
    [[self theTable] setDataSource:self];
    [[self theTable] setFrame:CGRectMake(0,0,320,416)];
    //set the rest of your table properties how you want them

    //Add TableView to current view
    [[self view] addSubview:theTable];
}

//UITableView Delegate Methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1; //However many sections your UITableView needs to have
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)[COLOR="red"]section[/COLOR]{
   return 5; //the number of rows in section # [COLOR="Red"]section[/COLOR]
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    static NSString* CellIdentifier = @"Cell";
    // create a new cell
   if (cell == nil) {
      cell = [[[UITableViewCell alloc] initWithStyle:UITableViewStyleDefault reuseIdentifier:CellIdentifier] autorelease];
   }
    cell.textLabel.text=@"Cell Text Goes Here";
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  NSInteger section=[indexPath section];
  NSInteger row=[indexPath row];
  //Do something based on this.
}

//Dealloc Code
-(void)dealloc{
    [super dealloc];
    [theTable release], theTable=nil;
}
by ZAPPnU
Thanks for the help and for giving just what was asked. From this I still have to look through and learn its not done for me but it is made clear and understandibal without all the extra clutter other examples give. thanks a ton.
Others are interested in:
best fps ever > mph to fps > minecraft low fps > fps tips > orange fps > top pc fps > eve fps > fps definition
Home | Contact | Privacy Policy |