我有兩個類:如何在xcode中使用兩個類的對象?
- ServiceProviderCompleteProfile
- 單選按鈕。
通過在ServiceProviderCompleteProfile
中導入RadioButton
類,我可以創建單選按鈕。
我已經聲明瞭與它自己的類中的單選按鈕有關的所有方法。
現在我想在選中RadioButton
時啓用我的ServiceProviderCompleteProfile
實例中的文本框。爲了達到這個目的,我也在RadioButton
中導入ServiceProviderCompleteProfile
。
我寫下了下面的代碼,但是ServiceProviderCompleteProfile
的對象沒有響應。
按鈕初始化
- (id)initWithFrame:(CGRect)frame andOptions:(NSArray *)options andColumns:(int)columns
{
self.radioButtons = [[NSMutableArray alloc] init];
if (self = [super initWithFrame:frame])
{
// Initialization code
int framex = 0;
framex = frame.size.width/columns;
int framey = 0;
framey = frame.size.height/([options count]/(columns));
int k = 0;
for(int i = 0; i < ([options count]/columns); i++)
{
for(int j = 0;j < columns; j++)
{
int x = framex*0.20;
int y = framey*0.20;
UIButton *btTemp = [[UIButton alloc]initWithFrame:CGRectMake(framex*j+x, framey*i+y, framex/2+x, framey/2+y)];
[btTemp addTarget:self action:@selector(radioButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
btTemp.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[btTemp setImage:[UIImage imageNamed:@"radio-off.png"] forState:UIControlStateNormal];
[btTemp setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
btTemp.titleLabel.font =[UIFont systemFontOfSize:11.f];
btTemp.titleLabel.numberOfLines=1;
btTemp.titleLabel.lineBreakMode=NSLineBreakByWordWrapping;
btTemp.titleLabel.textAlignment=NSTextAlignmentLeft;
[btTemp setTitle:[options objectAtIndex:k] forState:UIControlStateNormal];
btTemp.tag=j+1;
[self.radioButtons addObject:btTemp];
[self addSubview:btTemp];
k++;
}
}
}
return self;
}
按鈕操作
-(IBAction) radioButtonClicked:(UIButton *) sender
{
for(int i = 0; i < [self.radioButtons count]; i++)
{
[[self.radioButtons objectAtIndex:i] setImage:[UIImage imageNamed:@"radio-off.png"] forState:UIControlStateNormal];
}
genderButtonIndex=[sender tag];
[sender setImage:[UIImage imageNamed:@"radio-on.png"] forState:UIControlStateNormal];
ServiceProviderProfileViewController *svc=[[ServiceProviderProfileViewController alloc]init];
if([sender tag] == 3)
{
NSLog(@"%d",genderButtonIndex);
[email protected]"h";
svc.txtGratuity.userInteractionEnabled=YES;
}
else
{
svc.txtGratuity.userInteractionEnabled=NO;
}
}
使用協議或不使用協議通知 –
你可以把代碼片段? – Swapnil
@mobiSpace請檢查它。 – vivek