0

私はUIViewControllerを持っています。「リロード ボタン」として、navigationItem の rightBarButtonItem を使用します。リロード ボタンが押されると、アプリがリロードするデータを処理している間、leftBarButtonItem を使用してアクティビティ インジケーターを表示します。ここまでは大丈夫です。
ここにいくつかのコードがあります:

- (void)initSpinner {
    activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
    activityButton = [[UIBarButtonItem alloc] initWithCustomView: activityIndicator];
    self.navigationItem.leftBarButtonItem = activityButton;
}

- (void)spinBegin {
    [activityIndicator startAnimating];
}

- (void)spinEnd {
    [activityIndicator stopAnimating];
}
- (void)viewDidLoad {
     [self initSpinner];
     [super viewDidLoad];
    //more stuff going on here....
}
-(void) loadView{
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refreshFeeds:)];
}

ここで、ロジックを少し変更するように求められました。
rightBarButtonItem はそのままです。leftBarButtonItem はアクティビティ インジケーターを表示するためにまだ存在しますが、処理がない場合は、別のボタンを表示する必要があります。このボタンを押すと、新しいビューが表示されます (何らかの情報が表示されます)。
だから私はこれらの変更を行いました:

- (void)initSpinner {
    activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
    activityButton = [[UIBarButtonItem alloc] initWithCustomView: activityIndicator];
}

- (void)spinBegin {
    self.navigationItem.leftBarButtonItem = activityButton;
    [activityIndicator startAnimating];
}

- (void)spinEnd {
    [activityIndicator stopAnimating];
     self.navigationItem.leftBarButtonItem =infoBarButton; //= [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refreshFeeds:)] autorelease];
}
-(void) loadView{
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refreshFeeds:)];

    if (infoBarButton == nil){
        UIImage *buttonImage = [UIImage imageNamed:@"info.png"];
        UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [aButton setImage:buttonImage forState:UIControlStateNormal];
        aButton.frame = CGRectMake(0.0, 0.0, 25, 25);

        // Initialize the UIBarButtonItem
        infoBarButton = [[UIBarButtonItem alloc] initWithCustomView:aButton];

        // Set the Target and Action for aButton
        [aButton addTarget:self action:@selector(showInfo:) forControlEvents:UIControlEventTouchUpInside];


    }
    self.navigationItem.leftBarButtonItem = infoBarButton;
}

動作しているように見えますが (情報ボタンがあり、「リロード」を押すと、処理が完了するまで activityIndi​​cator が代わりに表示されます)、デバッガーコンソールで次のように表示されます。

__NSAutoreleaseNoPool(): Object 0x15ef30 of class UINavigationItem autoreleased with no pool in place - just leaking
 __NSAutoreleaseNoPool(): Object 0x1abd90 of class UIBarButtonItem autoreleased with no pool in place - just leaking
__NSAutoreleaseNoPool(): Object 0x1acb20 of class UIButton autoreleased with no pool in place - just leaking
__NSAutoreleaseNoPool(): Object 0x15ef30 of class UINavigationItem autoreleased with no pool in place - just leaking
__NSAutoreleaseNoPool(): Object 0x1ad030 of class UIActivityIndicatorView autoreleased with no pool in place - just leaking
__NSAutoreleaseNoPool(): Object 0x1ad030 of class UIActivityIndicatorView autoreleased with no pool in place - just leaking
__NSAutoreleaseNoPool(): Object 0x1a8c40 of class UINavigationButton autoreleased with no pool in place - just leaking
Object 0x941c of class NSCFString autoreleased with no pool in place - just leaking
//MORE similar messages following...

私は何を間違っていますか?誰かが助けてくれることを願っています...
よろしくお願いします。

4

2 に答える 2

0

あなたのプロパティはretain編集されていますか?あなたはやっていますがalloc] init...、それらをプロパティに割り当てた後に解放していません。メモリ管理ガイドをチェックすることをお勧めします

于 2011-05-24T14:36:01.240 に答える
0

私の推測では、バックグラウンド スレッドで「リロード」タスクを実行しており、完了するとspinEndバックグラウンド スレッドから呼び出します。バックグラウンド スレッドに自動解放プールが配置されていない場合、これらの警告が表示されます。

UIKitメインスレッドからのみメソッドを呼び出す必要があるため、次のようにして呼び出す必要がありますspinEnd

[self performSelectorOnMainThread:@selector(spinEnd) withObject:nil waitUntilDone:NO];
于 2011-05-24T14:37:20.070 に答える