Reputation: 16114
For some reason, some detail labels are not displayed. I have debugged program and I have checked, that the detail label text is normal, in this case it's a distance. I cut the text label text, so it does not overlap detail label. Also, I don't get a Distance is not filled! message in my code. This is screenshot(look at 2 and 4th rows):
This is my full code of that view controller:
#import "LpuListTableViewController.h"
#import "MedicineAppDelegate.h"
#import "ResultLPU.h"
#import "DetailViewController.h"
#import "MapViewController.h"
#import "CustomCellBackgroundView.h"
#import "CustomCellView.h"
#import "CSCustomCellBackgroundView.h"
#define allTrim( object ) [object stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet] ]
@implementation LpuListTableViewController
@synthesize myTableView;
@synthesize tableData;
@synthesize lpuArray,lpuArray1,lpuArray3,lpuArray6;
- (void) showAllOnMap {
useDelegate
appDelegate.singleLPUModeOn = NO;
MapViewController *mapViewController = [[MapViewController alloc] initWithNibName:@"MapViewController" bundle:nil];
[self.navigationController pushViewController:mapViewController animated:YES];
[mapViewController release];
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.rightBarButtonItem =[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"mapWhite.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(showAllOnMap)];
// Если нет интернета, игнорируем
useDelegate
if (!appDelegate.internetActive) {
NSString *msg = NoInternetMsg;
[appDelegate showResultViewWithText:msg fromView:self.view withSpeed:ResultViewSpeed];
return;
}
CGRect frame = CGRectMake(30.0, 40.0, 260.0, 150.0);
waitView = [[UIView alloc] initWithFrame:frame];
waitView.backgroundColor = AlertViewColor;
waitView.layer.cornerRadius = 15;
CGSize screenSize = [UIScreen mainScreen].bounds.size;
// Универсальное определение центра iPhone / iPad
CGFloat centerX = screenSize.width/2.0;
CGFloat centerY = (screenSize.height - 20.0 - 44.0 - 50.0)/2.0;
waitView.center = CGPointMake(centerX, centerY);
UILabel *aLabel = [[UILabel alloc]initWithFrame:CGRectMake(5.0,20.0,260.0,40.0)];
aLabel.backgroundColor = [UIColor clearColor];
aLabel.text = AlertViewText;
aLabel.textAlignment = UITextAlignmentCenter;
aLabel.font = [UIFont fontWithName:MyFont size:AlertViewTextSize];
[waitView addSubview:aLabel];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
indicator.center = CGPointMake(waitView.bounds.size.width * 0.5f, waitView.bounds.size.height * 0.7f);
[indicator startAnimating];
[waitView addSubview:indicator];
[indicator release];
[self.view addSubview:waitView];
[self performSelectorInBackground:@selector(loadDataInBackground) withObject:nil];
//NSLog(@"Count of lpuArray objects:%d", [lpuArray count]);
//tableData = [[NSMutableArray alloc]initWithArray:lpuArray];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void) loadDataInBackground {
useDelegate
// Set up a pool for the background task.
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
@try {
// Заполняем ЛПУ
int maxDist = APIMaximumDistanceToLPU;
NSLog(@"Selected Lpu Type:%@", appDelegate.selectedLpuType);
lpuArray = [[NSMutableArray alloc] init];
lpuArray1 = [[NSMutableArray alloc] init];
lpuArray3 = [[NSMutableArray alloc] init];
lpuArray6 = [[NSMutableArray alloc] init];
lpuArray = [appDelegate retrieveLPUofType:[appDelegate.selectedLpuType intValue]withMaxDist:maxDist];
// Разделяем lpuArray на несколько массивов в зависимости от того, какое расстояние там
lpuArray1 = [appDelegate selectFromLpuArray:lpuArray withMinDist:0 withMaxDist:1000];
lpuArray3 = [appDelegate selectFromLpuArray:lpuArray withMinDist:1000 withMaxDist:3000];
lpuArray6 = [appDelegate selectFromLpuArray:lpuArray withMinDist:3000 withMaxDist:7000];
[NSThread sleepForTimeInterval:testSleepInterval];
[self performSelectorOnMainThread:@selector(completeLoad) withObject:nil waitUntilDone:YES];
}
@finally {
[pool drain];
}
}
- (void) completeLoad {
[waitView removeFromSuperview];
[waitView release];
waitView = nil;
[myTableView reloadData];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
useDelegate
//[tableData removeAllObjects];
//[tableData addObjectsFromArray:lpuArray];
[myTableView reloadData];
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark - Table view data source
- (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 [lpuArray1 count];
break;
case 1:
return [lpuArray3 count];
break;
case 2:
return [lpuArray6 count];
break;
default:
return 0;
break;
}
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
switch (section) {
case 0:
{
if ([lpuArray1 count]>0)
return @"Не дальше 1 км";
else
return @"";
break;
}
case 1:
{
if ([lpuArray3 count]>0)
return @"Не дальше 3 км";
else
return @"";
break;
}
case 2:
{
if ([lpuArray6 count]>0)
return @"Не дальше 7 км";
else
return @"";
break;
}
default:
break;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
useDelegate
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
cell.textLabel.font = [UIFont fontWithName:MyFont size:MySize];
cell.detailTextLabel.font = [UIFont fontWithName:MyFont size:MySize];
/*cell.textLabel.backgroundColor = [UIColor clearColor];
cell.detailTextLabel.backgroundColor = [UIColor clearColor];
cell.contentView.backgroundColor = BigCellColor;*/
}
// Configure the cell...
NSUInteger row = [indexPath row];
NSUInteger section = [indexPath section];
// Configure the cell...
ResultLPU *resultLPU;
switch (section) {
case 0:
{
resultLPU = [lpuArray1 objectAtIndex:row];
break;
}
case 1:
{
resultLPU = [lpuArray3 objectAtIndex:row];
break;
}
case 2:
{
resultLPU = [lpuArray6 objectAtIndex:row];
break;
}
default:
break;
}
// Определение расстояния от пользователя до ЛПУ
float distanceMeters = [resultLPU distanceToLPU];
NSString *dist;
if (distanceMeters < 7000000.0) {
dist = [NSString stringWithFormat:@"%.0f м", distanceMeters];
}
else
{
dist = @"";
}
//NSString *nameAndDist = [resultLPU.name stringByAppendingString:dist];
//NSLog(@"dist:%@", dist);
//NSLog(@"nameAndDist:%@", nameAndDist);
if ([resultLPU.name length] >= MaxLPUCellTextLength) {
cell.textLabel.text = [NSString stringWithFormat:@"%@ ...", [resultLPU.name substringToIndex:MaxLPUCellTextLength]];
}
else
cell.textLabel.text = resultLPU.name;
cell.detailTextLabel.text = dist;
if ([cell.detailTextLabel.text isEqualToString:@""]) {
//NSLog(@"Distance is not filled! Dist = %@", dist);
NSLog(@"Distance is not filled! Dist = %f", distanceMeters);
}
else {
NSLog(@"Distance = %@", dist);
}
return cell;
}
/*- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return MyCellHeight;
}*/
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/
/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/
/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
useDelegate
NSUInteger row = [indexPath row];
NSUInteger section = [indexPath section];
ResultLPU *resultLPU;
switch (section) {
case 0:
resultLPU = [lpuArray1 objectAtIndex:row];
break;
case 1:
resultLPU = [lpuArray3 objectAtIndex:row];
break;
case 2:
resultLPU = [lpuArray6 objectAtIndex:row];
break;
default:
break;
}
appDelegate.selectedLPU = resultLPU;
// Формируем Description для данного ЛПУ
appDelegate.LPUdetails = [resultLPU generateHTML];
appDelegate.selectedItem = resultLPU.name;
appDelegate.latitudeLPU = [resultLPU.latitude doubleValue];
appDelegate.longitudeLPU = [resultLPU.longitude doubleValue];
appDelegate.detailsMode = 2;
appDelegate.favMode = NO;
/*appDelegate.latitudeLPU = 55.75;
appDelegate.longitudeLPU = 37.62;*/
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
@end
I've tried to use StyleSubtitle: it works. But I guess, why StyleValue1 doesn't?
Upvotes: 1
Views: 1164
Reputation: 2589
Can't add comments but I've seen this with strings that have line breaks in them.
cell.textLabel.text = [[myString componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]] componentsJoinedByString:@" "];
Should fix problem if myString has line breaks.
Upvotes: 0
Reputation: 2797
Try using UITableViewCellStyleSubtitle
.
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
Hope this helps
Upvotes: 1
Reputation: 7850
Perhaps it's because your distanceMeters for these rows is >= 7000000.0.
Change
NSLog(@"Distance is not filled! Dist = %@", dist);
to
NSLog(@"Distance is not filled! Dist = %f", distanceMeters);
And check the output.
Upvotes: 1