0

无法让这个警报实例显示在这个实现文件中,我就是找不到问题所在。

其他一切正常。

关于有什么问题的任何建议?

#import "BIDSingleComponentViewController.h"



@implementation BIDSingleComponentViewController

- (IBAction)buttonPressed
{
    NSInteger row = [self.singlePicker selectedRowInComponent:0];
    NSString *selected = self.characterNames[row];
    NSString *title = [[NSString alloc] initWithFormat:@"You selected %@", selected];

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
                                                    message:@"Thank you for choosing."
                                                   delegate:nil
                                          cancelButtonTitle:@"You're welcome."
                                          otherButtonTitles: nil];
    [alert show];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.characterNames = @[@"Luke", @"Leia", @"Han", @"Chewbacca", @"Artoo", @"Threepio", @"Lando"];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark
#pragma mark Picker Data Source Methods

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1; // Incompatible integer to pointer conversion
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return [self.characterNames count];
}

#pragma mark Picker Delegate Methods

-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    return self.characterNames[row];
}


@end

头文件:

#import <UIKit/UIKit.h>

@interface BIDSingleComponentViewController : UIViewController
<UIPickerViewDelegate, UIPickerViewDataSource>

@property (strong, nonatomic)IBOutlet UIPickerView *singlePicker;
@property (strong, nonatomic)NSArray *characterNames;

- (IBAction)buttonPressed;

@end
4

1 回答 1

-2

在您的头文件中确保包含 AlertViewDelegate:

@interface BIDSingleComponentViewController : UIViewController
<UIPickerViewDelegate, UIPickerViewDataSource, UIAlertViewDelegate>

此外,请务必将所有插座连接到它们在 IB 中的所属位置

于 2012-12-12T21:18:27.203 回答