Objective-C中的PickerView

时间:2013-04-14 10:04:39

标签: objective-c uipickerview textfield

输入以下链接后,设备只显示黑屏。任何人都可以请回答问题是什么?实际上,我想知道这个问题正在发生:

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row 
                                              inComponent:(NSInteger)component{
       picCode = [cameraCode objectAtIndex:row]; 
 }

源代码:

//testingProgram.h
#import <UIKit/UIKit.h>

@interface testingProgramViewController : UIViewController
        <UIPickerViewDelegate, UIPickerViewDataSource>
{
    NSTimer             *aTimer;
    NSString            *picCode;

    UIPickerView        *regionPicker;
    NSArray             *regionNames;
    NSArray             *cameraCode;
    UILabel             *testingLabel;
    UITextField         *regionTextField; 
    } 
@property (nonatomic, retain) IBOutlet UIPickerView *regionPicker; 
@property (nonatomic, retain) IBOutlet UILabel *testingLabel; 
@property (nonatomic, retain) IBOutlet UITextField *regionTextField; 
@property (nonatomic, retain) NSArray *regionNames; 
@property (nonatomic, retain) NSArray* cameraCode;

-(IBAction)textFieldReturn:(id)sender; 
@end

//testingProgram.m
#import "testingProgramViewController.h"

@interface testingProgramViewController () 
@property (weak, nonatomic) IBOutlet UIImageView *testingPic; 
@end

@implementation testingProgramViewController 
@synthesize regionPicker, regionNames, cameraCode; 
@synthesize testingLabel, regionTextField;

#pragma mark -
#pragma mark PickerView DataSource

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    return 1; 
    }
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    return [regionNames count]; 
    }
- (NSString *)pickerView:(UIPickerView *)pickerView
             titleForRow:(NSInteger)row
            forComponent:(NSInteger)component {
    return [regionNames objectAtIndex:row]; 
    }

#pragma mark -
#pragma mark PickerView Delegate
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row 
                                              inComponent:(NSInteger)component{
       picCode = [cameraCode objectAtIndex:row]; 
       }

- (void) obtainPic:(NSString *)picName{
    NSString *urlLink = [[NSString alloc] initWithFormat:@"http://tdcctv.data.one.gov.hk/%@.JPG", picName];
    NSURL *url = [NSURL URLWithString:urlLink];
    UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL:url]];
    self.testingPic.image = image; 
    }

-(IBAction)textFieldReturn:(id)sender {
    [sender resignFirstResponder]; 
    }

-(void)timerFired:(NSTimer *) theTimer {
    [self obtainPic:picCode]; 
    }

- (void)viewDidLoad {
    [super viewDidLoad];
    self.regionNames = [[NSArray alloc] initWithObjects:
                         @"Hong Kong Island", @"Kowloon", @"Tsuen Wan",
                         @"Tuen Mun & Tin Shui Wai", @"Tai Po, North and Yuen Long", @"Shatin & Ma On Shan", @"Lantau", nil];

    self.cameraCode = [[NSArray alloc] initWithObjects: @"H429F", @"K202F", @"TW117F", @"TI101F", @"BC702F", @"ST115F", @"TC551F", nil],

    picCode = @"H422F2";
    [self obtainPic:picCode];

    aTimer = [NSTimer scheduledTimerWithTimeInterval:60.0
                                              target:self
                                            selector:@selector(timerFired:)
                                            userInfo:nil
                                             repeats:YES]; 
    } 
@end

0 个答案:

没有答案