I am trying to create 3 cells of a table table using code (w / o nib). I'm having problems with the code. I guess I'm not getting this approach. Can someone advise me on the right way? Any help on this would be greatly appreciated!
Thanks!
Zhen hou
My code snippet is as follows:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // Return the number of sections. return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // Return the number of rows in the section. return 3; } // Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; int row = [indexPath row]; UITableViewCell *startCell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; UITableViewCell *durationCell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; UITableViewCell *radiusCell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; startCell.textLabel.text = @"Start:"; durationCell.textLabel.text = @"Duration:"; radiusCell.textLabel.text = @"radius"; if (row == 0) { return startCell; } else if (row == 1) { return durationCell; } return radiusCell; }
EDIT (19/05/11)
After going through your answers, I still cannot display any cells in my table view. Is this due to how I initialized my table?
After that, I have an animation to extend the tableView
[UIView animateWithDuration:0.3 animations:^{ [self.tableView setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-self.picker.frame.size.height)]; }];
Do you guys see any problems with this? Anything that causes my cell display to fail?
Thanks!
ginseng
source share