-(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
我可以将文本的格式更改为最适合代码的格式。让我知道。
我能做些什么来完成这项工作?