Конструктор UIAlertSheet принимает параметр otherButtonTitles как список varg. Вместо этого я хотел бы указать другие названия кнопок из NSArray. Возможно ли это?
то есть. Я должен это сделать:
id alert = [[UIActionSheet alloc] initWithTitle: titleString
delegate: self
cancelButtonTitle: cancelString
destructiveButtonTitle: nil
otherButtonTitles: button1Title, button2Title, nil];
Но так как я генерирую список доступных кнопок во время выполнения, я действительно хочу что-то вроде этого:
id alert = [[UIActionSheet alloc] initWithTitle: titleString
delegate: self
cancelButtonTitle: cancelString
destructiveButtonTitle: nil
otherButtonTitles: otherButtonTitles];
Прямо сейчас, я думаю, что мне нужно иметь отдельный вызов initWithTitle:
для 1 пункта, 2 элемента и 3 элемента. Вот так:
if ( [titles count] == 1 ) {
alert = [[UIActionSheet alloc] initWithTitle: titleString
delegate: self
cancelButtonTitle: cancelString
destructiveButtonTitle: nil
otherButtonTitles: [titles objectAtIndex: 0], nil];
} else if ( [titles count] == 2) {
alert = [[UIActionSheet alloc] initWithTitle: titleString
delegate: self
cancelButtonTitle: cancelString
destructiveButtonTitle: nil
otherButtonTitles: [titles objectAtIndex: 0], [titles objectAtIndex: 1], nil];
} else {
// and so on
}
Это много дублирующихся кодов, но это может быть разумно, так как у меня есть не более трех кнопок. Как я могу избежать этого?