IPhone : UITableView with customcell

on Wednesday, March 25, 2015

i am developing an iPhone app with tableview that act as a form with different sections. i also have 3 custom cell that contain Text Field, Segment Control and UISwitchView. my problem is that when i pressed on of the Switches or type some text in one of the textField, the same state of the Switch or text of the text Field reappear in different row and in different section.


Here is some images and part of my code to describe my problem:


enter image description here enter image description here enter image description here



-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 3;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSInteger rows = 0;
switch (section) {
case 0:
rows = 5;
break;
case 1:
rows = 11;
break;
case 2:
rows = 9;
break;
default:
break;
}

return rows;
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell;


// init cell
switch (indexPath.section) {
case 0:
if (indexPath.row>=0 && indexPath.row<=3)
{

cell = [tableView dequeueReusableCellWithIdentifier:@"text_field_cell"];

}
else if (indexPath.row == 4)
{
cell = [tableView dequeueReusableCellWithIdentifier:@"segment_cell"];

}
break;
case 1:
if (indexPath.row >=0 && indexPath.row <= 9)
{
cell = [tableView dequeueReusableCellWithIdentifier:@"switch_cell"];

}
else if (indexPath.row == 10)
{
cell = [tableView dequeueReusableCellWithIdentifier:@"text_field_cell"];

}
break;
case 2:
if (indexPath.row >=0 && indexPath.row <= 6)
{
cell = [tableView dequeueReusableCellWithIdentifier:@"switch_cell"];

}
else if (indexPath.row >=7 && indexPath.row <=8)
{
cell = [tableView dequeueReusableCellWithIdentifier:@"text_field_cell"];

}
break;

default:
break;
}

// init all text ..

return cell;

}

0 comments:

Post a Comment