2012-02-27 50 views
1

由於某些原因,某些詳細信息標籤不會顯示。我已經調試過程序,並且已經檢查過,細節標籤文本是正常的,在這種情況下,它是一個距離。我剪切了文本標籤文本,因此它不會與細節標籤重疊。另外,我沒有得到一個距離沒有填充!消息在我的代碼中。這是截圖(看2個第4行):DetailTextLabel不顯示在iPhone的某些行上TableView

enter image description here

這是我這個觀點控制器的全碼:

#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 

我試着使用StyleSubtitle:它的工作原理。但我想,爲什麼StyleValue1不?

​​

+0

你可以發佈剩餘的'UITableViewDataSource'和'UITableViewDelegate'方法嗎? – 2012-02-27 11:40:19

+0

是的,完成了。看看上面的代碼。我幾乎猜到了這個問題。我認爲,substringToIndex不適用於大寫字母。 – wzbozon 2012-02-28 09:35:26

回答

1

嘗試使用UITableViewCellStyleSubtitle

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 

希望這有助於

+0

是的,我試過了,它可以工作。我用新的截圖更新了問題。 – wzbozon 2012-02-27 11:33:43

+0

但它還不是一個解決方案。 – wzbozon 2012-02-27 11:40:43

1

也許是因爲你的distanceMeters這些行是> = 7000000.0。

變化

NSLog(@"Distance is not filled! Dist = %@", dist); 

NSLog(@"Distance is not filled! Dist = %f", distanceMeters); 

並檢查輸出。

+0

根據NSLog的說法,所有距離都很好,並且根據StyleSubtitle,一切正常。此子句從不爲TRUE: – wzbozon 2012-02-27 11:38:39

+0

if([cell.detailTextLabel.text isEqualToString:@「」]){NSLog(@「Distance is not filled!Dist =%@」,dist); } – wzbozon 2012-02-27 11:40:00

+0

它似乎是一個StyleValue1的錯誤 – wzbozon 2012-02-27 11:42:02

0

不能添加評論,但我已經看到這與他們有換行符的字符串。

cell.textLabel.text = [[myString componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]] componentsJoinedByString:@" "];

應該解決的問題,如果有的myString換行符。

相關問題