0

ボタンを押すたびに、mainController が [self.view addSubview: createCustomView.view] を呼び出しています。ここではすべて正常に動作します。問題は、後で取得するために、作成した各サブビューにタグを付ける必要があることです。私はすでにこれを試しました:

MainController.m

NSNumber *i;
createCustomView.view.tag = i; //readonly

そして、私が実際にやりたいことは次のとおりです。

int i;
[createCustomView.view setTag:i];

しかし、setTag メソッドは存在しません。私の質問は次のとおりです。私の場合、いくつかの問題を引き起こす識別子文字列を使用する以外に、これを行う方法はありますか?

前もって感謝します

コントローラーの .h ファイルは次のとおりです。

#import <Foundation/Foundation.h>
#import "TransactionButtonView.h"
@class TransactionButtonController;
@interface TransactionViewController : NSViewController
{
TransactionButtonController *transactionButtonController;
}
-(IBAction)createOnPushButton:(id)sender;
-(void)recalculatePositionOnRemove:(long)tag;

@property (nonatomic,assign) TransactionButtonController *transactionButtonController;

@end

コントローラーの .m ファイルは次のとおりです。

#import "TransactionViewController.h"
#import "TransactionButtonController.h"
#import "MainController.h"
@implementation TransactionViewController
@synthesize transactionButtonController;

-(IBAction)createOnPushButton:(id)sender
{
transactionButtonController = [[TransactionButtonController alloc] initWithNibName:@"TransactionButton" bundle:nil];
NSPoint originPoint;

for (int i=1; i <= [[self.view subviews]count]; i++) {
        originPoint.y = transactionButtonController.view.bounds.origin.y + self.view.bounds.size.height - transactionButtonController.view.bounds.size.height*i;
transactionButtonController.view.tag = i; // Here's the PROBLEM!!!
    [[transactionButtonController view]setIdentifier:[[NSNumber numberWithInt:i]stringValue]]; //here's the not good option

}
originPoint.x = transactionButtonController.view.bounds.origin.x;
[[transactionButtonController view] setFrameOrigin:originPoint];
[self.view addSubview:transactionButtonController.view];
[transactionButtonController sendVarsToButton:@"xxx" :@"591" :5 :87456356472456];

}

-(void)recalculatePositionOnRemove:(long)tag
{
NSPoint originPoint;
for (long i = tag; i<[[self.view subviews]count]; i++) {

    originPoint.y = transactionButtonController.view.bounds.origin.y +self.view.bounds.size.height - transactionButtonController.view.bounds.size.height*i;
    originPoint.x = transactionButtonController.view.bounds.origin.x;


     [[transactionButtonController.view viewWithTag:i+1] setFrameOrigin:originPoint];
}
}

@end 
4

1 に答える 1

0

ビューにタグを追加する場合は、次のようにします。

theView.tag = 1;

削除するには:

[[myParentView viewWithTag:1] removeFromSuperview]
于 2012-06-12T14:07:41.490 に答える