2012-12-12 54 views
0

不能得到这个警报实例在这个实现文件中显示,而我只是不能发现问题。UIAlertView中:警报不会显示

其他一切正常。

任何建议,有什么不对?

#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 
+0

与Xcode无关。重新标记。 – 2012-12-12 19:22:44

+2

您是否将IBAction按钮正确连接到IB的某个按钮操作? –

+0

这是问题所在。 DUH!谢谢。不会再犯这个错误! – pdenlinger

回答

-2

在你的头文件,确保您包括AlertViewDelegate:

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

另外,一定要所有出口连接到他们的IB

属于
+0

这是不正确的。该代理甚至不被该警报视图使用。 –

+0

在iphone开发的学习阶段并不重要。这是一个很好的习惯,所以当你想添加到UIAlertView时,你不会错过它。添加它并不会造成任何解构。我和下面的答案只是试图找出代码中的错误,因为就代码读取而言,一切都设置正确。这个问题甚至在代码中都没有,所以在这种情况下任何不是解构的东西都有帮助。 – nfoggia

+0

添加委托声明不能解决问题。无解构和正确是两个不同的东西,因此你的答案是不正确的。 –