【问题标题】:UIToolBar creating problem while application returns from backgroundUIToolBar 在应用程序从后台返回时创建问题
【发布时间】:2011-05-12 12:26:46
【问题描述】:

我正在使用 sdk 中的 initWithFrame: 方法初始化的视图中使用 uitoolbar。我的意思是我正在以编程方式添加工具栏。在多任务处理时,此工具栏会产生问题。任何人都可以给我一些解决方案或一束光来继续。我无法在 xib 中添加它,因为我使用的是自定义 uitablecontroller 类。我的代码如下:

-(void)viewDidLoad
{

[super viewDidLoad];    
actionToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 373, 320, 44)];  
[actionToolbar insertSubview:[[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"top-bar.png"]] autorelease] atIndex:0];

actionButton = [NotesList createSquareBarButtonItemWithTitle:@"Delete" target:self action:@selector(noAction:)];
flexibleSpace1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
flexibleSpace2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];    

composeButton = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(addNewGroup:)]autorelease];
composeButton.style = UIBarButtonItemStylePlain;    
[actionToolbar setItems:[NSArray arrayWithObjects:flexibleSpace1, flexibleSpace2, composeButton, nil]]; 
[self.view.superview addSubview:actionToolbar];

self.tableView.frame = CGRectMake(0, 0, 320, 400);  
[self.tableView setAllowsSelectionDuringEditing:YES];   
[flexibleSpace1 retain];
[flexibleSpace2 retain];
[actionButton retain];
[composeButton retain]; 
[self parseDataForThisFile];
}

【问题讨论】:

  • 想澄清您遇到的问题?除非你让我知道发生了什么,否则我无能为力
  • 你的问题到底是什么??
  • 我的问题是当应用程序从后台返回时,最初位于视图底部的工具栏移动到导航控制器下方的视图顶部。这只发生在多任务处理和调用 applicationWillEnterForeground 方法之后。

标签: iphone ios4 multitasking uitoolbar


【解决方案1】:

当应用程序从后台返回时,我通过设置标签栏控制器的框架来解决代码

【讨论】:

    【解决方案2】:

    即使您使用自定义 UITableViewController 子类,您也可以使用 NIB 文件。可以在 Interface Builder 中检查器的标识选项卡上指定要使用的确切类。
    (来源:peylow.se

    如果您在多任务处理时遇到问题,那么我怀疑您没有正确处理视图的卸载。您的应用可以在进入后台时从视图控制器中卸载视图以释放更多内存。

    确保在loadViewviewDidLoad 中设置/创建的任何连接也在viewDidUnload 中正确断开/释放,这一点很重要。否则,您的应用可能会发生奇怪和意想不到的事情。

    【讨论】:

    • 抱歉,我不能那样用。我试过了,但不能在那里更改类名。
    • @Dimple Panchal - 为什么?您编写类名的文本字段是从不只读的。请注意,如果您需要自定义设置,则必须根据需要覆盖 initWithCoder:awakeFromNib
    • 我的自定义类没有任何 xib 文件。所以可能就是这个原因。我不确定原因,但我怀疑这个原因。我一开始只试过这个。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-18
    • 2013-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多