I am creating a TableView which contains 20 rows.I have to add single labels to the even cells and i have to add two labels at odd cells.When i adding the desired labels and scrolling my table the labels disappars as i go down help me out.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// UITableView *cell=[tableView ]
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
if(indexPath.row%2==0)
{
UILabel *cellLabel=[[UILabel alloc]initWithFrame:CGRectMake(100, 40, 40, 40)];
cellLabel.text=#"o1";
[cell addSubview:cellLabel];
[cellLabel release];
}
else
{
UILabel *cellLabel1=[[UILabel alloc]initWithFrame:CGRectMake(100, 40, 40, 40)];
cellLabel1.text=#"e1";
[cell addSubview:cellLabel1];
[cellLabel1 release];
UILabel *cellLabel2=[[UILabel alloc]initWithFrame:CGRectMake(150, 40, 40, 40)];
cellLabel2.text=#"e2";
[cell addSubview:cellLabel2];
[cellLabel2 release];
}
}
Check this. This is same as your code I have just change Y position of each label and its working fine with scrolling also.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// UITableView *cell=[tableView ]
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
if(indexPath.row%2==0)
{
UILabel *cellLabel=[[UILabel alloc]initWithFrame:CGRectMake(100, 10, 40, 40)];
cellLabel.text=#"o1";
[cell addSubview:cellLabel];
}
else
{
UILabel *cellLabel1=[[UILabel alloc]initWithFrame:CGRectMake(100, 10, 40, 40)];
cellLabel1.text=#"e1";
[cell addSubview:cellLabel1];
UILabel *cellLabel2=[[UILabel alloc]initWithFrame:CGRectMake(150, 10, 40, 40)];
cellLabel2.text=#"e2";
[cell addSubview:cellLabel2];
}
}
return cell;
}
The two kinds of cells are different, so I would make different cell identifiers for each. Something like:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *EvenCellIdentifier = #"EvenCell";
static NSString *OddCellIdentifier = #"OddCell";
NSString* cellIdentifier = (indexPath.row % 2) == 0 ? EvenCellIdentifier : OddCellIdentifier;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
if(indexPath.row%2==0)
{
UILabel *cellLabel=[[UILabel alloc]initWithFrame:CGRectMake(100, 40, 40, 40)];
cellLabel.text=#"o1";
[cell addSubview:cellLabel];
[cellLabel release];
}
else
{
UILabel *cellLabel1=[[UILabel alloc]initWithFrame:CGRectMake(100, 40, 40, 40)];
cellLabel1.text=#"e1";
[cell addSubview:cellLabel1];
[cellLabel1 release];
UILabel *cellLabel2=[[UILabel alloc]initWithFrame:CGRectMake(150, 40, 40, 40)];
cellLabel2.text=#"e2";
[cell addSubview:cellLabel2];
[cellLabel2 release];
}
}
return cell;
}
Do it like this :
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// UITableView *cell=[tableView ]
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
UILabel *cellLabel=[[UILabel alloc]initWithFrame:CGRectMake(100, 40, 40, 40)];
cellLabel.text=#"o1";
cellLabel.tag = 2;
[cell addSubview:cellLabel];
[cellLabel release];
UILabel *cellLabel1=[[UILabel alloc]initWithFrame:CGRectMake(100, 40, 40, 40)];
cellLabel1.text=#"e1";
cellLable1.tag = 3;
[cell addSubview:cellLabel1];
[cellLabel1 release];
UILabel *cellLabel2=[[UILabel alloc]initWithFrame:CGRectMake(150, 40, 40, 40)];
cellLabel2.text=#"e2";
cellLabel2.tag = 4;
[cell addSubview:cellLabel2];
[cellLabel2 release];
}
UILabel *label1 = (UILabel *) [cell viewWithTag:2];
UILabel *label2 = (UILabel *) [cell viewWithTag:3];
UILabel *label3 = (UILabel *) [cell viewWithTag:4];
if (indexPath.row%2==0)
{
label1.hidden = FALSE;
label2.hidden = TRUE;
label3.hidden = TRUE:
}
else
{
label1.hidden = TRUE;
label2.hidden = FALSE;
label3.hidden = FALSE;
}
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *MyIdentifier = #"MyIdentifier";
static NSString *MyIdentifier1 = #"MyIdentifier1";
UITableViewCell *cell;
if(indexPath.row % 2 != 0)
{
cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
}
else
{
cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier1];
}
if(cell == nil)
{
if(indexPath.row % 2 != 0)
{
cell=[self reuseTableViewCellWithIdentifier:MyIdentifier withIndexPath:indexPath];
}
else
{
cell=[self reuseTableViewCellWithIdentifier:MyIdentifier1 withIndexPath:indexPath];
}
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
-(UITableViewCell *)reuseTableViewCellWithIdentifier:(NSString *)identifier withIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell=[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]autorelease];
if([identifier isEqualToString:#"MyIdentifier"])
{
UILabel *l1=[[[UILabel alloc]initWithFrame:CGRectMake(5, 5, 30, 20)]autorelease];
l1.backgroundColor=[UIColor redColor];
[cell.contentView addSubview:l1];
UILabel *l2=[[[UILabel alloc]initWithFrame:CGRectMake(65, 5, 30, 20)]autorelease];
l2.backgroundColor=[UIColor grayColor];
[cell.contentView addSubview:l2];
}
else
{
UILabel *l1=[[[UILabel alloc]initWithFrame:CGRectMake(5, 5, 30, 20)]autorelease];
l1.backgroundColor=[UIColor blueColor];
[cell.contentView addSubview:l1];
}
return cell;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row%2==0)
{
static NSString *CellIdentifier = #"CustomCell";
CustomCell *cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:#"CustomCell" owner:self options:nil];
for (id currentObject in topLevelObjects)
{
if ([currentObject isKindOfClass:[UITableViewCell class]])
{
cell = (CustomCell *) currentObject;
break;
}
}
}
cell.capitalLabel.text =[capitals objectAtIndex:indexPath.row];
cell.stateLabel.text = [states objectAtIndex:indexPath.row];
cell.t1.delegate=self;
cell.t1.tag=indexPath.row;
cell.t1.text=[arrTemp objectAtIndex:indexPath.row];
cell.s1.backgroundColor=[UIColor grayColor];
cell.s1.contentSize=CGSizeMake(1000, 40);
return cell;
}
else
{
static NSString *CellIdentifier1 = #"CustomCell1";
CustomCell1 *cell1 = (CustomCell1 *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
if (cell1 == nil)
{
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:#"CustomCell1" owner:self options:nil];
for (id currentObject in topLevelObjects)
{
if ([currentObject isKindOfClass:[UITableViewCell class]])
{
cell1 = (CustomCell1 *) currentObject;
break;
}
}
}
cell1.l1.text=#"alok";
return cell1;
}
}
static NSString *CellIdentifier = #"Cell";
static NSString *CellIdentifierButton = #"CellButton";
UITableViewCell *cell = nil;
if (indexPath.section <=2)
{
if(indexPath.section==2&&indexPath.row==4)
{
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifierButton];
}
else
{
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
}
}
if (cell == nil)
{
if (indexPath.section <=2)
{
if(indexPath.section==2&&indexPath.row==4)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifierButton];
UIButton *b1 = [[UIButton alloc]initWithFrame:CGRectMake(200, 10, 300, 80)];
[b1 setBackgroundColor:[UIColor redColor]];
[b1 setTag:501];
[cell.contentView b1];
UIButton * b2 = [[UIButton alloc]initWithFrame:CGRectMake(200, 120, 300, 80)];
[b2 setBackgroundColor:[UIColor redColor]];
[b2 setTag:502];
[cell.contentView b2];
}
else
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 250, 44)];
[label setBackgroundColor:[UIColor clearColor]];
[label setTag:500];
[cell.contentView addSubview:label];
//end for section 1
//for section2
}
//end for section 2
}
}
}
//====setting the values===//
if (indexPath.section ==0)
{
UILabel *label = (UILabel *)[cell.contentView viewWithTag:500];
if (label) {
[label setText:[arr1 objectAtIndex:indexPath.row]];
}
}
if (indexPath.section ==1)
{
UILabel *label = (UILabel *)[cell.contentView viewWithTag:500];
if (label) {
[label setText:[arr2 objectAtIndex:indexPath.row]];
}
}
Related
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = #"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
// NSLog(#"msgcnt123 %#\n",[messageCount objectAtIndex:indexPath.row]);
NSArray *seperateArray = [[clist objectForKey:[[clist allKeys]objectAtIndex:indexPath.row]]componentsSeparatedByString:#"#"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
// NSLog(#"key %#\n",[[clist allKeys]objectAtIndex:indexPath.row]);
cell.textLabel.text = [seperateArray objectAtIndex:0];
// cell.textLabel.text = [contactlist objectAtIndex:indexPath.row];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
// NSLog(#"sep %#\n",seperateArray);
if (![[seperateArray objectAtIndex:1] isEqualToString:#"0"]) {
NSLog(#"msgCount %#\n",[seperateArray objectAtIndex:1]);
lblCnt = [[UILabel alloc]initWithFrame:CGRectMake(260, 13, 20, 20)];
lblCnt.backgroundColor = [UIColor lightGrayColor];
lblCnt.textColor = [UIColor blackColor];
lblCnt.text = [seperateArray objectAtIndex:1];
lblCnt.textAlignment = UITextAlignmentCenter;
lblCnt.layer.masksToBounds = YES;
lblCnt.layer.cornerRadius = 2.0f;
[cell.contentView addSubview:lblCnt];
lblCnt.tag = 1000;
}
else
{
/*NSLog(#"msgCount1 %#\n",[seperateArray objectAtIndex:1]);
[lblCnt removeFromSuperview];
lblCnt.hidden = YES;*/
for (UIView *view in [cell.contentView subviews])
{
if (view.tag == 1000)
{
[view removeFromSuperview];
}
}
}
return cell;
}
I am displaying contact name with a label in UITableView.The label displaying number of received messages for each contact.My view name is chatViewcontroller.If I am in that view that label count does not updated.For ex:For contact name "John" label count is "2".When John receives a message that label count should be updated as "3".It is not happening so.It is updated if i move come from another view.Is it possible to Update tableView chatviewController itself?.
Make sure that you updated your datasource(clist) and then call [tableview reloadData]
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = #"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
// NSLog(#"msgcnt123 %#\n",[messageCount objectAtIndex:indexPath.row]);
NSArray *seperateArray = [[clist objectForKey:[[clist allKeys]objectAtIndex:indexPath.row]]componentsSeparatedByString:#"#"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
// NSLog(#"key %#\n",[[clist allKeys]objectAtIndex:indexPath.row]);
cell.textLabel.text = [seperateArray objectAtIndex:0];
// cell.textLabel.text = [contactlist objectAtIndex:indexPath.row];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
// NSLog(#"sep %#\n",seperateArray);
if (![[seperateArray objectAtIndex:1] isEqualToString:#"0"]) {
NSLog(#"msgCount %#\n",[seperateArray objectAtIndex:1]);
lblCnt = [[UILabel alloc]initWithFrame:CGRectMake(260, 13, 20, 20)];
lblCnt.backgroundColor = [UIColor lightGrayColor];
lblCnt.textColor = [UIColor blackColor];
lblCnt.text = [seperateArray objectAtIndex:1];
lblCnt.textAlignment = UITextAlignmentCenter;
lblCnt.layer.masksToBounds = YES;
lblCnt.layer.cornerRadius = 2.0f;
[cell.contentView addSubview:lblCnt];
}
else
{
NSLog(#"msgCount1 %#\n",[seperateArray objectAtIndex:1]);
[lblCnt removeFromSuperview];
lblCnt.hidden = YES;
}
return cell;
}
I have added a label in each row which displays number of messages received.In didSelect method i make label count zero so i can disappear label from tableView.In case of more than one row in table view label not disappear.
The simple and dirty method to reach what u want is to use a tag
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = #"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
NSArray *seperateArray = [[clist objectForKey:[[clist allKeys]objectAtIndex:indexPath.row]]componentsSeparatedByString:#"#"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text = [seperateArray objectAtIndex:0];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (![[seperateArray objectAtIndex:1] isEqualToString:#"0"]) {
lblCnt = [[UILabel alloc]initWithFrame:CGRectMake(260, 13, 20, 20)];
lblCnt.backgroundColor = [UIColor lightGrayColor];
lblCnt.textColor = [UIColor blackColor];
lblCnt.text = [seperateArray objectAtIndex:1];
lblCnt.textAlignment = UITextAlignmentCenter;
lblCnt.layer.masksToBounds = YES;
lblCnt.layer.cornerRadius = 2.0f;
[cell.contentView addSubview:lblCnt];
//Add a tag
lblCnt.tag = 1000;
}
else
{
/*
NSLog(#"msgCount1 %#\n",[seperateArray objectAtIndex:1]);
[lblCnt removeFromSuperview];
lblCnt.hidden = YES;
*/
for (UIView *view in [cell.contentView subviews]) {
if (view.tag == 1000) {
[view removeFromSuperview];
}
}
}
return cell;
}
and select the view based on the tag.
in my app i have an UITableView with 120 rows and every row has 1 UItextfeilds and 1 Buttons as show in the code bellow :
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier] autorelease];
}
else
{
}
UITextField *NameTextField = [[UITextField alloc] initWithFrame:CGRectMake(0, 10, 230, 28)];
NameTextField.borderStyle = UITextBorderStyleRoundedRect;
NameTextField.delegate = self;
NameTextField.textColor = UIColorFromRGB(0x2A1807);
NameTextField.font = [UIFont fontWithName:#"Helvetica" size:(17.0)];
NameTextField.font = [UIFont boldSystemFontOfSize:20];
NameTextField.tag = [indexPath row ];
NSString *temp = [self.sectionNames objectAtIndex:[indexPath section]];
NameTextField.text = [[self.myDataArray objectForKey:temp] objectAtIndex:[indexPath row]];
[cell.contentView addSubview:NameTextField];
[NameTextField release];
UIButton * aBtn = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *wijzigImage = [UIImage imageNamed:#"btn_delete.png"];
aBtn.frame = CGRectMake(240, 10, 28, 26);
[aBtn setImage:wijzigImage forState:UIControlStateNormal];
[aBtn addTarget:self action:#selector(deleteCustomCellWithUIButton:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:aBtn];
return cell;
}
i have noticed that the Scrolling is slow and It doesn't go fluently.
any idea ?
Thanks
That's because you create textfields and buttons every time, add it inside if (cell == nil) {...}. The only thing that should be left outside that if is textField text setting.
Btw, your textfield leaks.
I found the solution :
if (cell == nil) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier] autorelease];
}
else
{
UITextField *oldTextField = (UITextField *)[cell.contentView viewWithTag:999];
[oldTextField removeFromSuperview];
UIButton *oldBtn = (UIButton *)[cell.contentView viewWithTag:888];
[oldBtn removeFromSuperview];
}
NameTextField.tag = 999;
aBtn.tag = 88;
I have 2 columns in my table:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSUInteger const kLeftLabel =100;
static NSUInteger const kRightLabel=101;
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
CGRect leftF = CGRectMake(10, 5, 100, 30);
CGRect rightF = CGRectMake(120, 5, 100, 30);
left = [[[UILabel alloc] initWithFrame:leftF] autorelease];
left.tag = kLeftLabel; // assumming #define kLeftLabel 100
[cell.contentView addSubview:left];
right = [[[UILabel alloc] initWithFrame:rightF] autorelease];
right.tag = kRightLabel;
[cell.contentView addSubview:right];
}
else{
left= (UILabel*)[cell.contentView viewWithTag:kLeftLabel];
right = (UILabel*)[cell.contentView viewWithTag:kRightLabel];
}
profileDB *Obj = [appDelegate.profileArray objectAtIndex:indexPath.row];
left.text = Obj.profileName;
right.text = Obj.id;
return cell;
}
I want to read the right column's text only for a selected cell.
Is this possible?
First, You have to find out the selected cell.
- (void) tableView:(UITableView*)tableview didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
UITableViewCell *cell = [tableview cellForRowAtIndexPath:indexPath];
for(UILabel *lbl in [cell.contentView subviews])
{
if(([lbl isKindOfClass:[UILabel class]]) && ([lbl tag] == 101))
{
NSString *str = lbl.textLabel.text;
}
}
}
If you have added subviews on cell, the you can specific label's text by using their tag
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
if(indexPath.row < 8)
{
CGRect textRect = CGRectMake(10, 10, 300, 31);
UITextField *myfield = [[UITextField alloc]initWithFrame:textRect];
myfield.borderStyle = UITextBorderStyleRoundedRect;
myfield.font = [UIFont systemFontOfSize:22.0];
myfield.adjustsFontSizeToFitWidth = YES;
myfield.minimumFontSize = 2.0;
myfield.clearButtonMode = UITextFieldViewModeWhileEditing;
myfield.keyboardType = UIKeyboardTypeDefault;
myfield.autocorrectionType= UITextAutocorrectionTypeNo;
myfield.autocapitalizationType=UITextAutocapitalizationTypeNone;
myfield.returnKeyType=UIReturnKeyDone;
[self. addSubview:myfield];
}
return cell;
}
I wrote the above code for displaying textboxes in UITableViewCell (up to eight cells ) but the text box is displaying in the first cell only is there anything wrong in the above code?
The problem is this line:
[self.addSubview:myfield];
Change this to:
[cell.contentView addSubview: myfield];
[myfield release];
However, I agree with Björn Marschollek about design, so here is how this method should look:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifierWithTextBox = #"CellWithTextBox";
static NSString *CellIdentifierOther = #"CellOther";
UITableViewCell *cell;
if(indexPath.row < 8)
{
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifierWithTextBox];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifierWithTextBox] autorelease];
CGRect textRect = CGRectMake(10, 10, 300, 31);
UITextField *myfield = [[UITextField alloc]initWithFrame:textRect];
myfield.borderStyle = UITextBorderStyleRoundedRect;
myfield.font = [UIFont systemFontOfSize:22.0];
myfield.adjustsFontSizeToFitWidth = YES;
myfield.minimumFontSize = 2.0;
myfield.clearButtonMode = UITextFieldViewModeWhileEditing;
myfield.keyboardType = UIKeyboardTypeDefault;
myfield.autocorrectionType= UITextAutocorrectionTypeNo;
myfield.autocapitalizationType=UITextAutocapitalizationTypeNone;
myfield.returnKeyType=UIReturnKeyDone;
[cell.contentView addSubview: myfield];
[myfield release];
}
}
else
{
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifierOther];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifierOther] autorelease];
}
}
return cell;
}