2012-12-12 55 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

添加委託聲明不能解決問題。無解構和正確是兩個不同的東西,因此你的答案是不正確的。 –