次のリンクを入力すると、デバイスに黒い画面が表示されます。誰が何が問題なのか答えてもらえますか? 実際、この部分で問題が発生しているのではないかと思っています。
-(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