-(void)dismissActionSheet:(id)sender {
[actionSheet dismissWithClickedButtonIndex:0 animated:YES];
}
-(IBAction) pressButton:(id)sender{
actionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:nil
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
CGRect pickerFrame = CGRectMake(0, 40, 0, 0);
UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame];
pickerView.showsSelectionIndicator = YES;
pickerView.dataSource = pickerArray;
pickerView.delegate = self;
[actionSheet addSubview:pickerView];
[pickerView release];
UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"OK"]];
closeButton.momentary = YES;
closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
closeButton.tintColor = [UIColor blackColor];
[closeButton addTarget:self action:@selector(dismissActionSheet:) forControlEvents:UIControlEventValueChanged];
[actionSheet addSubview:closeButton];
[closeButton release];
[actionSheet showInView:[[UIApplication sharedApplication] keyWindow]];
[actionSheet setBounds:CGRectMake(0, 0, 320, 485)];
[actionSheet release];
}
ボタンを押すとキーボードのようにポップアップするピッカーを作成しました。今、私は自分のサイトから配列を取り込もうとしています。すなわちhttp://www.mywebsite.com/app/array.txt
これは私がこれまでに持っているものです:
- (void)viewDidLoad{
NSURL *url = [NSURL URLWithString:@"http://www.tntmax.com/app/gQL420pt.txt"];
NSString *x = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
self.pickerArray = x;
[x release];
うまくいかないようです。私はさまざまな方法を試しましたが、これは最新の試みです。
私のウェブサイトのページは次のようになります。
@"object1", @"thing2", @"person3", @"stuff4", nil
テキストの形式を、コードに最適な形式に変更できます。お知らせ下さい。
これを機能させるにはどうすればよいですか?