gpt4 book ai didi

iphone - DetailTextLabel 未显示在 iPhone TableView 的某些行上

转载 作者:行者123 更新时间:2023-11-29 11:15:50 26 4
gpt4 key购买 nike

由于某些原因,一些细节标签没有显示。我已经调试了程序并且我已经检查过,细节标签文本是正常的,在这种情况下它是一个距离。我剪切了文本标签文本,因此它不会与详细信息标签重叠。另外,我没有得到 Distance is not filled !我的代码中的消息。这是屏幕截图(看第 2 行和第 4 行):

enter image description here

这是我的那个 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

我试过使用 StyleSubtitle:它有效。但我想,为什么 StyleValue1 没有?

enter image description here

最佳答案

可能是因为这些行的 distanceMeters >= 7000000.0。

改变

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

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

并检查输出。

关于iphone - DetailTextLabel 未显示在 iPhone TableView 的某些行上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9464120/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com