大家好! 我们的应用程序存在问题。 UITabBarController有4个选项卡,在开始时加载。当应用程序在iPhone 4上启动更多三天时,第一个选项卡不显示UITableViewController。但其他标签效果很好。从cashe卸载后,所有选项卡都会显示。
@implementation MyProfileController
- (id)init {
self = [super init];
if (self != nil)
{
self.tabBarItem = [[UITabBarItem alloc]initWithTitle:JKMyProfile image:
[UIImage imageWithCGImage:[[UIImage imageNamed:@"1.png"]CGImage] scale:2.0 orientation:UIImageOrientationUp]
tag:0];
UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithTitle:@"Save" style:UIBarButtonSystemItemSave target:self action:@selector(save_clicked:)];
self.navigationItem.rightBarButtonItem = saveButton;
[saveButton release];
db = [[DBConnect alloc] init];
table = [[UITableViewController alloc]initWithStyle:UITableViewStyleGrouped];
table.view.backgroundColor = [UIColor clearColor];
table.view.frame = CGRectMake(0.0, 0.0, 320.0, 480.0);
table.tableView.scrollEnabled = NO;
table.tableView.delegate = self;
table.tableView.dataSource = self;
firstName = [[UITextField alloc] initWithFrame: CGRectMake (25.0, 22.0, 280.0, 50.0)];
firstName.font = [ UIFont boldSystemFontOfSize:16.0];
firstName.placeholder = @"First Name";
[table.view addSubview:firstName];
waitingControl = [[UISegmentedControl alloc] initWithFrame:CGRectMake(10, 180, 300, 40)];
[waitingControl insertSegmentWithTitle:@"Boy/Girl" atIndex:0 animated:NO];
[waitingControl insertSegmentWithTitle:@"Twins" atIndex:1 animated:NO];
NSMutableArray *Temp1 = [[[NSMutableArray alloc] init] autorelease];
Temp1 = [db dbqueryselect: 1: @"select WaitingFor from User where Id_user = 1 and WaitingFor > ''"];
if ([Temp1 count] > 0)
{
if ([[Temp1 objectAtIndex:0] isEqual:@"Boy/Girl"])
waitingControl.selectedSegmentIndex = 0;
else
waitingControl.selectedSegmentIndex = 1;
}
[table.view addSubview:waitingControl];
[self.view addSubview:table.view];
}
return self;
}
- (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];
}
switch ([indexPath indexAtPosition:0])
{
case(0):
{
cell.selectionStyle = UITableViewCellSelectionStyleNone;
NSMutableArray *Temp1 = [[[NSMutableArray alloc] init] autorelease];
Temp1 = [db dbqueryselect: 1: @"select FirstName from User where Id_user = 1 and FirstName > ''"];
if ([Temp1 count] > 0)
firstName.text = [Temp1 objectAtIndex:0];
break;
}
case (1):
{
impregDate = [[UILabel alloc] initWithFrame: CGRectMake (200.0, 14.0, 95.0, 20.0)];
impregDate.font = [ UIFont boldSystemFontOfSize:16.0];
impregDate.textColor = [UIColor grayColor];
impregDate.textAlignment = UITextAlignmentRight;
NSMutableArray *Temp3 = [[[NSMutableArray alloc] init] autorelease];
Temp3 = [db dbqueryselect: 1: @"select ImpregnationDate from User where Id_user = 1 and ImpregnationDate > ''"];
if ([Temp3 count] > 0)
impregDate.text = [NSString stringWithFormat:@"%@",[Temp3 objectAtIndex:0]];
else
{
NSString *dateString;
NSDateFormatter *formatter;
formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd"];
dateString = [formatter stringFromDate:[NSDate date]];
impregDate.text = dateString;
[formatter release];
}
cell.textLabel.text = @"Date";
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[cell addSubview:impregDate];
break;
}
}
return cell;
}
答案 0 :(得分:1)
它可能与内存警告有关。您应该在viewDidLoad
中创建表控制器。
发生内存警告时,视图被释放。下次控制器变为可见时,您应该重新创建所有视图层次结构。