UITableViewCell changes accessory view changes on scroll - ios

I am trying to create tableview with UISwitch for some specific rows and AccessoryDisclosureIndicator for rest of cells.
I get the desired result as one check in following code.But the issue is , when i scroll the table view abruptly then the position of switch changes .. Which is undesired how can i get rid of this.
Please do reply to this thread
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
int _fontSize = fontSize;
NSArray *switchSettings = [[NSUserDefaults standardUserDefaults] arrayForKey:#"switchGeneralSettings"];
NSLog(#"switch settings :%#",switchSettings);
static NSString *cellIdentifier = #"generalSettingsTableViewCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
NSLog(#"*******************1*************");
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
// code to additionally configure cell for multiple other UI components..
if(indexPath.row == 3 || indexPath.row == 4 || indexPath.row == 5 || indexPath.row == 6 || indexPath.row == 7)
{
NSLog(#"switch*******************%d*************",indexPath.row);
switchObj = [[UISwitch alloc] initWithFrame:CGRectZero];
switchObj.tag = indexPath.row + 20002;
cell.accessoryView = switchObj;
[switchObj addTarget: self action: #selector(flip:) forControlEvents:UIControlEventValueChanged];
[switchObj release];
}
else
{
NSLog(#"indicator*******************%d*************",indexPath.row);
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
}
else
{
if(indexPath.row == 3 || indexPath.row == 4 || indexPath.row == 5 || indexPath.row == 6 || indexPath.row == 7)
{
NSLog(#"*******************2*************");
countSwitch = 0;
switchObj = (UISwitch *)[cell.contentView viewWithTag:indexPath.row + 20002];
// switch
[switchObj setOn:NO];
if ([switchSettings count]>0) {
NSString *settingState = [switchSettings objectAtIndex:countSwitch];
if ([settingState isEqualToString:#"ON"]) {
[switchObj setOn:YES];
}
}
countSwitch++;
}
}
// confiure the cell here...
NSLog(#"*******************3*************");
NSString *cellTextLabel = [listGeneralSettings objectAtIndex:indexPath.row];
cell.textLabel.text = cellTextLabel;
cell.textLabel.font = [UIFont systemFontOfSize:_fontSize];
cell.detailTextLabel.text = [listDetailGeneralSettings objectAtIndex:indexPath.row];
NSLog(#" cell.detailTextLabel.text :%#", cell.detailTextLabel.text);
NSLog(#"*******************end*************");
return cell;
}

Here cellone is tableviewCell, in that cell you can add uiswitch
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
(NSIndexPath*)indexPath{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
// ... some text label stuff deleted here.
cell.opaque = NO;
cell.selectionStyle = UITableViewCellSelectionStyleGray;
[cell setBackgroundColor: [UIColor colorWithPatternImage:[UIImage imageNamed:#"row_2_blank.png"]]];
// [cell prepareForReuse];
}
if (indexPath.row == 0)
{
selectAllB.tag=100;
[selectAllB addTarget:self action:#selector(click:)forControlEvents:UIControlEventTouchUpInside];
[cellOne setBackgroundColor: [UIColor colorWithPatternImage:[UIImage imageNamed:#"row_2_blank.png"]]];
cellOne.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cellOne;
}
return cell;
}
likewise you can use many tableview cell inwhich you can add ui elements accordingly

You're only updating the cell when it's first created. You need to update it every time. Try it like this:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
int _fontSize = fontSize;
NSArray *switchSettings = [[NSUserDefaults standardUserDefaults] arrayForKey:#"switchGeneralSettings"];
NSLog(#"switch settings :%#",switchSettings);
static NSString *cellIdentifier = #"generalSettingsTableViewCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
NSLog(#"*******************1*************");
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}
// code to additionally configure cell for multiple other UI components..
// configure the cell here...
if(indexPath.row == 3 || indexPath.row == 4 || indexPath.row == 5 || indexPath.row == 6 || indexPath.row == 7)
{
NSLog(#"switch*******************%d*************",indexPath.row);
switchObj = [[UISwitch alloc] initWithFrame:CGRectZero];
switchObj.tag = indexPath.row + 20002;
cell.accessoryView = switchObj;
[switchObj addTarget: self action: #selector(flip:) forControlEvents:UIControlEventValueChanged];
[switchObj release];
}
else
{
NSLog(#"indicator*******************%d*************",indexPath.row);
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
if(indexPath.row == 3 || indexPath.row == 4 || indexPath.row == 5 || indexPath.row == 6 || indexPath.row == 7)
{
NSLog(#"*******************2*************");
countSwitch = 0;
switchObj = (UISwitch *)[cell.contentView viewWithTag:indexPath.row + 20002];
// switch
[switchObj setOn:NO];
if ([switchSettings count]>0) {
NSString *settingState = [switchSettings objectAtIndex:countSwitch];
if ([settingState isEqualToString:#"ON"]) {
[switchObj setOn:YES];
}
}
countSwitch++;
}
NSLog(#"*******************3*************");
NSString *cellTextLabel = [listGeneralSettings objectAtIndex:indexPath.row];
cell.textLabel.text = cellTextLabel;
cell.textLabel.font = [UIFont systemFontOfSize:_fontSize];
cell.detailTextLabel.text = [listDetailGeneralSettings objectAtIndex:indexPath.row];
NSLog(#" cell.detailTextLabel.text :%#", cell.detailTextLabel.text);
NSLog(#"*******************end*************");
return cell;
}

Related

DetailText loading in incorrect space in UITableViewCell

Its hard to explain to images will help. When the UITableView first loads, the detailText is above the textLabel - as such:
But when you move the tableView around a bit, it corrects itself, as such:
Here is my code for adjusting for everything I feel is applicable:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"cell"];
cell.detailTextLabel.numberOfLines = 0;
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"cell"];
}
if (indexPath.row == 0){
cell.textLabel.text = #"Two";
cell.detailTextLabel.text = [self.rules objectForKey:#"two"];
}
if (indexPath.row == 1){
cell.textLabel.text = #"Three";
}
if (indexPath.row == 2){
cell.textLabel.text = #"Four";
}
if (indexPath.row == 3){
cell.textLabel.text = #"Five";
}
if (indexPath.row == 4){
cell.textLabel.text = #"Six";
}
if (indexPath.row == 5){
cell.textLabel.text = #"Seven";
}
if (indexPath.row == 6){
cell.textLabel.text = #"Eight";
}
if (indexPath.row == 7){
cell.textLabel.text = #"Nine";
}
if (indexPath.row == 8){
cell.textLabel.text = #"Ten";
}
if (indexPath.row == 9){
cell.textLabel.text = #"Jack";
}
if (indexPath.row == 10){
cell.textLabel.text = #"Queen";
}
if (indexPath.row == 11){
cell.textLabel.text = #"King";
}
if (indexPath.row == 12){
cell.textLabel.text = #"Ace";
}
CGRect frame = tableView.frame;
UIButton *addButton = [[UIButton alloc] initWithFrame:CGRectMake(frame.size.width-70, 10, 50, 30)];
[addButton setTitle:#"Get" forState:UIControlStateNormal];
addButton.titleLabel.font = [UIFont fontWithName:#"Avenir-Black" size:14.0f];
addButton.backgroundColor = [UIColor redColor];
[cell.contentView addSubview:addButton];
cell.detailTextLabel.numberOfLines = 0;
cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap;
[cell.detailTextLabel sizeToFit];
return cell;
}
The row height:
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *str = [self.rules objectForKey:#"two"];
CGSize size = [str sizeWithFont:[UIFont fontWithName:#"Avenir" size:17] constrainedToSize:CGSizeMake(280, 999) lineBreakMode:NSLineBreakByWordWrapping];
return size.height + 40;
}

ios TableViewcell set checkmark but scrolling time checkmark is Auto hide and try to solve it creash

i have a tableview cell and this is binding from one array and select to multipal cell and set to checkmark but when i scroll table the checkmark is auto hide
and then i search on stackoverflow and i find one answier
the link is
UITableview accessory type disappear while scrolling
i tried this code but app is crash Here is my code, please Help me
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = #"FirstTableViewCell";
FirstTableViewCell *cell = (FirstTableViewCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"FirstTableViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
if(tableView ==nurseTypeTable){
cell.lbl1.text = [arrayNurseType objectAtIndex:indexPath.row];
if(_nurseArray.count != nil){
// if (_nurseArray == nil || [_nurseArray count] == 0) {
NSNumber *rowNsNum = [_nurseArray objectAtIndex:indexPath.row];
if ( [arrayNurseType containsObject:rowNsNum] )
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
}
return cell;
}
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString * cellValue=nil;
if (tableView==nurseTypeTable) {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
//Here is for Check
if(cell.accessoryType == UITableViewCellAccessoryNone) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
//here i add in array
cellValue=[arrayNurseType objectAtIndex:indexPath.row];
NSLog(#"%#",cellValue);
[_nurseArray addObject:cellValue];
NSLog(#"%#",_nurseArray);
}
//Here is for uncheck
else {
cellValue=[arrayNurseType objectAtIndex:indexPath.row];
[_nurseArray removeObject:cellValue];
cell.accessoryType = UITableViewCellAccessoryNone;
NSLog(#"Remove Array %#",_nurseArray);
}
// [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
in function cellForRowAtIndexPath **
NSNumber *rowNsNum = [_nurseArray objectAtIndex:indexPath.row];** is creash on debug time
arrayNurseType = [NSMutableArray arrayWithObjects:#" Nurse ",#"One",nil]
You should use
if(tableView ==nurseTypeTable){
cell.lbl1.text = [arrayNurseType objectAtIndex:indexPath.row];
if(_nurseArray.count != nil){
// if (_nurseArray == nil || [_nurseArray count] == 0) {
if ( [_nurseArray containsObject:indexPath] )
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
}
return cell;
}
}

How can I solve this delegate error?

I have a delegate, but it doesn't work without the other delegate line in it:
- (id)initWithData:(NSData *)data delegate:(id <ParseOperationDelegate>)theDelegate {
self = [super init];
if (self != nil) {
self.dataToParse = data;
self.delegate = theDelegate;
}
appDelegate = (XMLAppDelegate *)[[UIApplication sharedApplication] delegate];
return self;
}
It should load data in a Cell but the data isn't shown before the first scroll. What can I do?
EDIT:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"productCell";
static NSString *PlaceholderCellIdentifier = #"placeholderCell";
int nodeCount = [appDelegate.products count];
if (nodeCount == 0 && indexPath.row == 0) {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:PlaceholderCellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:PlaceholderCellIdentifier];
cell.detailTextLabel.textAlignment = UITextAlignmentCenter;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
cell.detailTextLabel.text = #"Loading...";
return cell;
}
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
if (nodeCount > 0) {
XMLProductView *listedProduct = [appDelegate.products objectAtIndex:indexPath.row];
cell.textLabel.text = listedProduct.name;
// cell.detailTextLabel.text = appRecord.artist;
if (!listedProduct.productImage) {
if (self.tableView.dragging == NO && self.tableView.decelerating == NO) {
[self startImageDownload:listedProduct forIndexPath:indexPath];
}
UIImageView *listedImage = (UIImageView *)[cell viewWithTag:1];
listedImage.image = [UIImage imageNamed:#"Placeholder.png"];
}
else {
UIImageView *listedImage = (UIImageView *)[cell viewWithTag:1];
listedImage.image = listedProduct.productImage;
}
}
return cell;
}
your code seems that its waiting for some event, or some files to get fetched or downloaded, so you will need to call [tableview reloadData]; when this data is downloaded,
I cant figure it out from the code, but my guts tells me this
1st:
that you are waiting for data from int nodeCount = [appDelegate.products count]; to be ready, so you will need to have some sort of delegate that gets called when this data is ready
2nd:
you are waiting for an image to get downloaded here [self startImageDownload:listedProduct forIndexPath:indexPath], so when this actually get downloaded you will need to set the image to that cell or reloadData on the table
That is what i can figure out from the code.

UITextField display issue in TableView cell

I created at least 10 cells with each UITextField on it, for registration page. When I insert the words on the textfield in the first cell, and when I scrolled the tableView, the textfield which is in another cell show up the word that I just typed.
Below is my code. The textField data which I input is looping, which is caused by dequeueReusableCellWithIdentifier... How can I solve this problem? Thank you very much.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"RCell";
RegisterCell *cell = (RegisterCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
cell = [[[RegisterCell alloc] initWithFrame:CGRectMake(0, 0, 280, 44) reuseIdentifier:CellIdentifier] autorelease];
if(indexPath.section == 0){
NSDictionary *rowData = [self.regisLabel objectAtIndex:[indexPath row]];
NSString *mainLabel = [NSString stringWithFormat:#"%#", [rowData objectForKey:#"regisLbl"]];
cell.registerLabel.text = mainLabel;
UITextField *valTxtField = [[UITextField alloc] initWithFrame:CGRectMake(120, 5, 180, 30)];
valTxtField.font = [UIFont fontWithName:#"Futura-CondensedExtraBold" size:18.0];
valTxtField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
valTxtField.delegate = self;
valTxtField.returnKeyType = UIReturnKeyDone;
valTxtField.autocorrectionType = UITextAutocorrectionTypeNo;
valTxtField.autocapitalizationType = UITextAutocapitalizationTypeNone;
if(indexPath.row == 0)
{
valTxtField.text = #"";
emailTxtFld = valTxtField; //emailTxtFld is global variable
}
if(indexPath.row == 1)
{
valTxtField.text = #"";
reEmailTxtFld = valTxtField; //reEmailTxtFld is global variable
}
[cell.contentView addSubview:valTxtField];
[valTxtField release];
}
else if(indexPath.section == 1){
NSDictionary *rowData = [self.regisLabel objectAtIndex:[indexPath row]+10];
NSString *mainLabel = [NSString stringWithFormat:#"%#", [rowData objectForKey:#"regisLbl"]];
cell.registerLabel.text = mainLabel;
cell.registerTextField.enabled = NO;
}
else if(indexPath.section == 2){
if(indexPath.row == 0){
NSDictionary *rowData = [self.regisLabel objectAtIndex:[indexPath row]+11];
NSString *mainLabel = [NSString stringWithFormat:#"%#", [rowData objectForKey:#"regisLbl"]];
cell.registerLabel.text = mainLabel;
cell.registerTextField.enabled = NO;
}
}
return cell;
}
An easy way is to just remove all subviews from the cells contentView before you add subviews, example:
for (UIView *subview in [cell.contentView subviews])
[subview removeFromSuperview];
A more efficient way would be to do all the creation of cells inside the if (cell == nil) statement, but that depends on how many cells you have in the table.
The right implementation is to move the creation of any view whithin if (cell == nil)
Like so:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"RCell";
RegisterCell *cell = (RegisterCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UITextField *valTxtField;
if (cell == nil)
{
cell = [[[RegisterCell alloc] initWithFrame:CGRectMake(0, 0, 280, 44) reuseIdentifier:CellIdentifier] autorelease];
if(indexPath.section == 0){
valTxtField = [[UITextField alloc] initWithFrame:CGRectMake(120, 5, 180, 30)];
valTxtField.font = [UIFont fontWithName:#"Futura-CondensedExtraBold" size:18.0];
valTxtField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
valTxtField.delegate = self;
valTxtField.returnKeyType = UIReturnKeyDone;
valTxtField.autocorrectionType = UITextAutocorrectionTypeNo;
valTxtField.autocapitalizationType = UITextAutocapitalizationTypeNone;
valTxtField.tag = 100;
[cell.contentView addSubview:valTxtField];
[valTxtField release];
}
}
valTxtField = (UITextField *)[cell.contentView viewWithTag:100];
if(indexPath.section == 0){
NSDictionary *rowData = [self.regisLabel objectAtIndex:[indexPath row]];
NSString *mainLabel = [NSString stringWithFormat:#"%#", [rowData objectForKey:#"regisLbl"]];
cell.registerLabel.text = mainLabel;
if(indexPath.row == 0)
{
valTxtField.text = #"";
emailTxtFld = valTxtField; //emailTxtFld is global variable
}
if(indexPath.row == 1)
{
valTxtField.text = #"";
reEmailTxtFld = valTxtField; //reEmailTxtFld is global variable
}
}
else if(indexPath.section == 1){
NSDictionary *rowData = [self.regisLabel objectAtIndex:[indexPath row]+10];
NSString *mainLabel = [NSString stringWithFormat:#"%#", [rowData objectForKey:#"regisLbl"]];
cell.registerLabel.text = mainLabel;
cell.registerTextField.enabled = NO;
}
else if(indexPath.section == 2){
if(indexPath.row == 0){
NSDictionary *rowData = [self.regisLabel objectAtIndex:[indexPath row]+11];
NSString *mainLabel = [NSString stringWithFormat:#"%#", [rowData objectForKey:#"regisLbl"]];
cell.registerLabel.text = mainLabel;
cell.registerTextField.enabled = NO;
}
}
return cell;

UISwitch shows up on other cells! Glitch?

I have 5 seperate sections in a table, 2 of the sections have customizable cells, when in EDITING mode, 2 of the sections produce an additional cell that will add a new cell to the list. My problem is that when I invoke edit mode, the UISwitch glitches! and decides to jump around, VERY SIMPLE code, just have NO IDEA why the UISwitch is jumping to different cells in DIFFERENT SECTIONS when it should NOT!
static NSInteger kCustomTextTag = 1;
static NSInteger kServiceTag = 3;
static NSInteger kConnectTag = 4;
static NSInteger kVibrateTag = 1;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
Profile_ManagerAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
cell.hidesAccessoryWhenEditing = YES;
}
UISwitch *swService = nil;
swService = [[[UISwitch alloc] initWithFrame:CGRectMake(195, 8, 160, 27)] autorelease];
[swService addTarget:self action:#selector(serviceSwAction:) forControlEvents:UIControlEventValueChanged];
swService.tag = kServiceTag;
UISwitch *swConnect = nil;
swConnect = [[[UISwitch alloc] initWithFrame:CGRectMake(195, 8, 160, 27)] autorelease];
[swConnect addTarget:self action:#selector(connectSwAction:) forControlEvents:UIControlEventValueChanged];
swConnect.tag = kConnectTag;
UISwitch *swVibrate = nil;
swVibrate = [[[UISwitch alloc] initWithFrame:CGRectMake(195, 8, 160, 27)] autorelease];
[swVibrate addTarget:self action:#selector(vibrateSwAction:) forControlEvents:UIControlEventValueChanged];
swVibrate.tag = kVibrateTag;
if(indexPath.section == 0)
{
//CGRectMake Method (x, y, width, height)
custProfileNameLabel = [[[UITextField alloc] initWithFrame:CGRectMake(10, 11, 290, 21)] autorelease];
custProfileNameLabel.tag = kCustomTextTag;
custProfileNameLabel.textAlignment = UITextAlignmentLeft;
[cell.contentView addSubview:custProfileNameLabel];
custProfileNameLabel.backgroundColor = [UIColor clearColor];
custProfileNameLabel.userInteractionEnabled = NO;
custProfileNameLabel.placeholder = #"Custom Profile Name";
custProfileNameLabel.autocapitalizationType = UITextAutocapitalizationTypeWords;
custProfileNameLabel.clearButtonMode = UITextFieldViewModeWhileEditing;
//UIKeyboardTypeDefault;
cell.selectionStyle = UITableViewCellEditingStyleNone;
CustomProfile *cProf = [CustomProfile alloc];
cell.textLabel.text = [cProf tName];
}
if(indexPath.section == 1)
{
if(indexPath.row == ([[appDelegate serviceArray] count]) && self.editing){
cell.textLabel.text = #"Add a Service";
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryNone;
swService.hidden = YES;
return cell;
}else{
swService.hidden = NO;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryNone;
cell.textLabel.text = [[appDelegate serviceArray] objectAtIndex:indexPath.row];
}
[cell addSubview:swService];
}
if(indexPath.section == 2)
{
if(indexPath.row == ([[appDelegate connectArray] count]) && self.editing){
cell.textLabel.text = #"Add a Connection";
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryNone;
swConnect.hidden = YES;
return cell;
}else{
swConnect.hidden = NO;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryNone;
cell.textLabel.text = [[appDelegate connectArray] objectAtIndex:indexPath.row];
}
[cell addSubview:swConnect];
}
if(indexPath.section == 3)
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *myPlistPath = [documentsDirectory stringByAppendingPathComponent:#"ProfileManager.plist"];
NSDictionary *plistDict = [[NSDictionary alloc] initWithContentsOfFile:myPlistPath];
NSString *value;
value = [plistDict objectForKey:#"Custom Ringtone"];
if(indexPath.row == ([[appDelegate ringArray] count]) && self.editing){
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryNone;
}else{
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
cell.textLabel.text = value;
}
if(indexPath.section == 4)
{
if(indexPath.row == 0 && self.editing)
{
//cell.userInteractionEnabled = NO;
cell.accessoryType = UITableViewCellAccessoryNone;
cell.textLabel.text = #"Vibrate";
swVibrate.hidden = YES;
}else{
swVibrate.hidden = NO;
//cell.accessoryType = UITableViewCellAccessoryNone;
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
cell.textLabel.text = #"Vibrate";
}
[cell.contentView addSubview:swVibrate];
}
return cell;
}
Screenshot
Well, the reason this glitch was made possible is because the Controls were created when creating the cell, so it just continued to create additional controls when view appeared.
If you are receiving this glitch too, make sure you create the controls at ViewDidLoad, or call a void, just dont create the controls in the cellForRowAtIndexPath:
Nothing freaky is going on. This is normal behavior. Note the line UITableViewCell *cell = dequeueReusableCellWithIdentifier ... The tableview controller keeps a queue of previously used cells for efficiency purposes, and when you scroll a new section of the tableview into view, it may return a previously used cell for you to reuse (in which case the value of the returned cell would not be nil). If that used cell originally had a uiswitch embedded in it, you'll get that switch back again, even if the current cell doesn't use it.
You need to check in your cell allocation code whether the cell being given back to you is an existing one or not, and remove the switch if it's present and you don't want it.
Howard

Resources