Каждый раз, когда я нажимаю кнопку, mainController вызывает [self.view addSubview: createCustomView.view]. Здесь все отлично. Проблема в том, что мне нужно поместить тег в каждый созданный subview, чтобы получить их позже. Я уже пробовал это:NSViewController.view (Subviews) setTag
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
На самом деле я не могу заставить это работать. Каждый раз, когда я получаю ошибку: «метод setter необходим для назначения ...» или «Readonly». –
Вы @synthesize? – self
Да, да. Может быть, вы хотите увидеть весь код? –