블로그 이미지
Sunny's

calendar

1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

Notice

'CustomUITableViewCell'에 해당되는 글 1

  1. 2011.09.22 Insert CustomUITableViewCell in UITableVew on Row Selected
2011. 9. 22. 10:02 IPhone

this tutorial show how to insert custom cell as uitableviewcell when any row on uitableview is selected.
first created view controller with uitableview ,then create custom cell as you like ,you can subclass uitableviewcell and created one.

the trick here is when row is selected we reload table and return new cell view for selected row.thats all

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
 
	if(selectedCellIndexPath != nil
	   && [selectedCellIndexPath isEqual:indexPath] ) {
		static NSString *CustomCellIdentifier = @"CustomCell";
		CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier: CustomCellIdentifier];
 
		if (cell == nil) { NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell"
																		owner:self options:nil];
			for (id oneObject in nib) if ([oneObject isKindOfClass:[CustomCell class]])
				cell = (CustomCell *)oneObject;
		}
 
		[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
		cell.label.text=[self.tableData objectAtIndex:indexPath.row];
		cell.textField.text=[self.tableData objectAtIndex:indexPath.row];
		return cell;
 
	}
 
 
    static NSString *CellIdentifier = @"Cell";
 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    cell.textLabel.text=[self.tableData objectAtIndex:indexPath.row];
    // Configure the cell...
 
 
    return cell;
}
 
 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // Navigation logic may go here. Create and push another view controller.
    self.selectedCellIndexPath = indexPath; 
	if(selectedCellIndexPath != nil
	   && [selectedCellIndexPath isEqual:indexPath]) {
 
		[self.tableView reloadData];
	}
}


you can download the code from below.
InsertCustomCellOnTableRow

Related posts:

  1. Lazy loading Custom UITableViewCell
  2. UISplitViewController, MultipleDetailViews with Navigation Controller
  3. Dropdown in iPhone-iPad

    출처 : 
    http://kshitizghimire.com.np/insert-customuitableviewcell-in-uitablevew-on-row-selected/ 
posted by Sunny's
prev 1 next