Note that there are some explanatory texts on larger screens.

plurals
  1. POa way to remove empty value from the tableview?
    text
    copied!<p>New to objective c. I am using <code>NSArray</code> to populate my <code>UITableView</code>. is there a way to remove the blank from the array and from the <code>cell.textLabel.text</code>. This is what i have done:</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; alTableView.delegate = self; alTableView.dataSource = self; NSArray *BusRoute = alightDesc; int i; int count = [BusRoute count]; for (i = 0; i &lt; count; i++) { NSDictionary *STEPS = [dic valueForKey:@"STEPS"]; alDescArray = [[STEPS valueForKey:@"AlightDesc"] retain]; boardDescArray = [[STEPS valueForKey:@"BoardDesc"] retain]; NSLog(@"boardDescArray = %@", boardDescArray); serviceID = [[STEPS valueForKey:@"ServiceID"] retain]; } } - (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]; } cell.textLabel.font = [UIFont systemFontOfSize:14]; //Change this value to adjust size cell.textLabel.numberOfLines = 10; cell.textLabel.text = [NSString stringWithFormat:@"Walk to and board at %@\nTake Bus Service = %@\nAlight Destination = %@",[boardDescArray objectAtIndex:indexPath.row], [serviceID objectAtIndex:indexPath.row], [alDescArray objectAtIndex:indexPath.row]]; NSLog(@"cell = %@", cell.textLabel.text); return cell; } </code></pre> <p>At the second cell print out, Walk to and board at <code>(Null)</code> is there a way to remove that sentence from the table?</p> <p>Results:</p> <pre><code>alDescArray = ( "OPP", "OPP", "OPP" ) boardDescArray = ( "BLK", "AFT", "" ) serviceID = ( 66, 43, 72 ) cell = Walk to and board at BLK 7 Take Bus Service = 11 Alight Destination = BLK 11 cell = Walk to and board at Take Bus Service = 3 Alight Destination = BLK 16 cell = Walk to and board at BLK 38 Take Bus Service = 9 Alight Destination = AA </code></pre> <hr> <p><strong>Update Ans</strong></p> <pre><code>- (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]; } cell.textLabel.font = [UIFont systemFontOfSize:14]; //Change this value to adjust size cell.textLabel.numberOfLines = 10; NSString *boardDesc = [boardDescArray objectAtIndex:indexPath.row]; NSString *serviceId = [serviceID objectAtIndex:indexPath.row]; NSString *alDesc = [alDescArray objectAtIndex:indexPath.row]; NSLog(@"serviceId - %@",serviceId); NSString *resultString2 = [NSString stringWithString:@""]; //make a check before making the string if ([boardDesc length]&gt;0) { resultString2 =[resultString2 stringByAppendingFormat:@"Walk to and board at %@,",boardDesc]; } if ([serviceId length]&gt;0) { resultString2 =[resultString2 stringByAppendingFormat:@"Take Bus Service %@: ",serviceId]; } if ([alDesc length]&gt;0) { resultString2 =[resultString2 stringByAppendingFormat:@"Alight Destination %@: ",alDesc]; } //string that doesnot print null values NSLog(@"resultString2 - %@",resultString2); cell.textLabel.text = resultString2; NSLog(@"cell = %@", cell.textLabel.text); return cell; } </code></pre>
 

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