Note that there are some explanatory texts on larger screens.

plurals
  1. POiPhone - Button getting dissappeard
    primarykey
    data
    text
    <p>I am having a table view . On a cell I am adding a button ( UIButton customButton ). But sometimes that button disappears. I checked the whole code , nowhere I am modifying the button properties. I have also retained the button . Actually button is still there but not visible. If I click on buttons location the call back function on button gets called. I don't know what's going wrong. I have checking this from 2 days but didn't find any bug. I am pasting below the code for that. If anyone has faced this issue , please help me !!!</p> <pre><code> logOutBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [logOutBtn setImage:[UIImage imageNamed:@"BLUE.png"] forState:UIControlStateNormal]; [logOutBtn setFrame:CGRectMake(100, 2, 100, 35)]; [logOutBtn addTarget:self action:@selector(SignOut) forControlEvents:UIControlEventTouchUpInside]; [logOutBtn retain]; </code></pre> <p>Adding the complete code.</p> <pre><code> - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // Return the number of sections. return 3; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // Return the number of rows in the section. switch (section) { case 0: return 1; break; case 1: return 4; break; case 2: return 1; break; } return 0; </code></pre> <p>}</p> <pre><code> - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == 0) { return 90; } return 50; } </code></pre> <p>// Customize the appearance of table view cells.</p> <pre><code> - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *CellIdentifier = [NSString stringWithFormat:@"%d%d",indexPath.section,indexPath.row]; int newCellFlag = 0; UITableViewCell *cell; UILabel * titleLabel; UIImageView * logoView; UIButton * infoBtn; // Configure the cell... switch (indexPath.section) { case 0: //add the custom button for cities cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { newCellFlag = 1; cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; } if (newCellFlag == 1) { if (indexPath.row==0) { /*cell.textLabel.textAlignment = UITextAlignmentCenter; cell.textLabel.text = @"My city subscriptions";*/ cell.selectionStyle = UITableViewCellSelectionStyleNone; logoView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"logo.png"]]; logoView.frame = CGRectMake(5, 0, 295, 80); [cell.contentView addSubview:logoView]; [logoView release]; infoBtn = [UIButton buttonWithType:UIButtonTypeInfoDark]; infoBtn.frame = CGRectMake(270, 75, 15, 15); [cell.contentView addSubview:infoBtn]; [infoBtn addTarget:self action:@selector(infoView:) forControlEvents:UIControlEventTouchUpInside]; } if (indexPath.row ==1) { cell.detailTextLabel.textAlignment = UITextAlignmentCenter; cell.detailTextLabel.textColor = [UIColor orangeColor]; cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.detailTextLabel.text = @"Add cities"; //[cell.contentView addSubview:_AddCitiesButton]; } } break; case 1: cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { newCellFlag = 1 ; cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease]; } //add the custom button for cities if (newCellFlag == 1) { if (indexPath.row ==0) { cell.textLabel.text = @"User name"; cell.detailTextLabel.text =[[NSUserDefaults standardUserDefaults] objectForKey:@"user_name"]; cell.selectionStyle = UITableViewCellSelectionStyleNone; } if (indexPath.row ==1) { cell.textLabel.text = @"Credits left"; cell.detailTextLabel.text = (connected ? [NSString stringWithFormat:@"$ %@",[self getUserMoney]] : @"Not Available."); cell.selectionStyle = UITableViewCellSelectionStyleNone; //[cell.contentView addSubview:_creditsLabel]; } if (indexPath.row ==2) { cell.textLabel.text = @"Current City"; cell.detailTextLabel.text = [[NSUserDefaults standardUserDefaults]objectForKey:@"current_city_name"]; cell.selectionStyle = UITableViewCellSelectionStyleNone; //[cell.contentView addSubview:_currentCity]; } if (indexPath.row == 3) { /* titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(100, 5, 100, 35)]; titleLabel.text = @"Log out"; titleLabel.backgroundColor = [UIColor clearColor]; titleLabel.textColor = [UIColor purpleColor]; titleLabel.font = [UIFont fontWithName:@"Verdana" size:15.5]; titleLabel.font = [UIFont boldSystemFontOfSize:15.5]; [cell.contentView addSubview:titleLabel]; [titleLabel release]; */ [cell.contentView addSubview:logOutBtn]; cell.selectionStyle = UITableViewCellSelectionStyleNone; } } break; case 2: //add the custom button for cities cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { newCellFlag = 1; cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease]; } if (newCellFlag ==1 ) { cell.textLabel.text = @"App Version"; cell.detailTextLabel.text = @"1.0"; cell.selectionStyle = UITableViewCellSelectionStyleNone; } break; default: break; } if(newCellFlag == 1) { if (indexPath.section == 0) { CommonBG * bg = [[CommonBG alloc]initWithFrame:cell.bounds]; cell.backgroundView = bg; cell.backgroundView.alpha = 0.0;//[UIColor clearColor]; [bg release]; } else { CommonBG * bg = [[CommonBG alloc]initWithFrame:cell.bounds]; cell.backgroundView = bg; [bg release]; cell.textLabel.backgroundColor = [UIColor clearColor]; cell.detailTextLabel.backgroundColor = [UIColor clearColor]; cell.layer.cornerRadius = 10; } } return cell; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload