我有一個動態創建按鈕的循環。創建一個能夠檢查按鈕標題的功能
for (int b = 0; b < _currentPlayerTeams.count; b++)
{
HNTeamObject *team = _currentPlayerTeams[b];
CGFloat buttonY = 168 + ((b + 1) * distanceBetweenButtons) - 23;
NSString *buttonTitle = [NSString stringWithFormat:@"%@ %@",team.teamName, team.seriesName];
UIButton *button = [[UIButton alloc] init];
button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundImage:[UIImage imageNamed:@"images.png"] forState:UIControlStateNormal];
button.titleLabel.textColor = [UIColor blackColor];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
button.backgroundColor = [UIColor clearColor];
[button addTarget:self
action:@selector(chooseTeamOne:)
forControlEvents:UIControlEventTouchUpInside];
[button setTitle: buttonTitle forState:UIControlStateNormal];
button.titleLabel.text = (@"%@", buttonTitle);
button.frame = CGRectMake(labelAndButtonX, buttonY, 268.0, 46.0);
[self.view addSubview:button];
}
我需要做一個函數,可以作爲選擇器,爲每個按鈕創建並查看按鈕的標題。由於我在循環中製作按鈕,所以它們是本地的,不會出現在我創建的另一個函數中。任何幫助,將不勝感激。我提前道歉,因爲我對編碼非常陌生,而且對於正在發生的事情沒有很好的把握。謝謝。
我知道如何登錄此,不知道如何在chooseTeamOne方法的更遠處執行此操作,因爲UIButton - 按鈕是本地創建的,並且它不會在chooseTeamOne方法中識別此操作。 ChooseTeamOne是 - (IBAction)chooseTeamOne(id)發件人 – aviators54 2015-03-24 22:40:34
很簡單,謝謝。我真的很感激它! – aviators54 2015-03-24 22:43:06