title: iPhone/Objective-C UIActionSheet with programmatically added buttons
body: <p>I have a <code>UIActionSheet</code> that contains buttons that are programmatically added depending on whether a property contains a value or not.</p>
  
  <p>This is the code I'm currently using:</p>
  
  <pre><code>- (IBAction)infoButtonTap:(id)sender {
      MyObject *obj = (MyObject *)[self.dataSource objectAtIndex:self.pageControl.currentPage];
  
      if (obj != nil) {
          UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Details"
                                                                   delegate:self
                                                          cancelButtonTitle:nil
                                                     destructiveButtonTitle:nil
                                                          otherButtonTitles:nil];
  
          // Programatically add Other button titles if they exist.
          if (obj.firstProperty) {
              [actionSheet addButtonWithTitle:@"Dosomething"];
          }
  
          if (obj.secondProperty) {
              [actionSheet addButtonWithTitle:@"Dosomethingelse"];
          }
  
          [actionSheet addButtonWithTitle:@"Static button"];
  
          actionSheet.cancelButtonIndex = [actionSheet addButtonWithTitle:@"Cancel"];
  
          [actionSheet showInView:self.view.window];
          [actionSheet release];
      }
  }
  
  - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
      MyObject *obj = (MyObject *)[self.dataSource objectAtIndex:self.pageControl.currentPage];
  
      switch (buttonIndex) {
          case 0: // Dosomething
              break;
          case 1: // Dosomethingelse
              break;
          case 2: // Static button
              break;
          default:
              break;
      }
  }
  </code></pre>
  
  <p>The problem is, how do I account for the fact that one of the properties may be null and handle that within the <code>clickedButtonAtIndex:</code>? The index values will change. I have around 4 or 5 different buttons, each displayed depending on whether a property contains a value of some sort.</p>