更改从UIPickerView中选择的NSURL

时间:2012-06-27 18:34:23

标签: ios uipickerview feed nsurl

在我的应用中,我将“feed link”加载到tableView中。它运作良好。但现在我需要使用UIPickerView更改该链接。

在我的viewDidLoad中,此代码用于将Feed项目加载到tableview

第一次运作良好。

// Parse
feedURL = [NSURL URLWithString:FEEDSFULLPAGE];

feedParser = [[MWFeedParser alloc] initWithFeedURL:feedURL];
feedParser.delegate = self;
feedParser.feedParseType = ParseTypeFull; // Parse feed info and all items
feedParser.connectionType = ConnectionTypeAsynchronously;
[feedParser parse];

使用此代码,我从导航栏上的UIPickerView调用UIBarButtonItem

- (void) showPicker:(id)sender {

self.tableView.scrollEnabled = false;
categorie.enabled = NO;

UIColor *myColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
rect = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[rect setBackgroundColor:myColor];
[self.view addSubview:rect];

pickerviewToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 542, 320, 40)];
pickerviewToolbar.barStyle = UIBarStyleBlackTranslucent;
pickerviewToolbar.tintColor = nil;
[pickerviewToolbar sizeToFit];

UIBarButtonItem *cancelButton = [[[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(AnnullaPickerView)] autorelease];

UIBarButtonItem *flexSpace = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil] autorelease];

UIBarButtonItem *doneButton = [[[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(categoriaSelezionata:)] autorelease];

[pickerviewToolbar setItems:[NSArray arrayWithObjects:cancelButton, flexSpace, doneButton,  nil]];

pickerView.delegate = self;
pickerView.showsSelectionIndicator = YES;    // note this is default to NO

// Add the picker
pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0,585,0,0)];

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];
CGAffineTransform transform = CGAffineTransformMakeTranslation(0, -400);
pickerView.transform = transform;
pickerviewToolbar.transform = transform;

[self.view addSubview:pickerView];
[self.view addSubview:pickerviewToolbar];

[UIView commitAnimations];

[pickerView release];
[pickerviewToolbar release];
}

现在当选择了一行UIPIckerView时,我这样做:

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{

if ([[dataArray objectAtIndex:row] isEqual:@"Ultime"]) {

    feedURL = [NSURL URLWithString:@"http://www.tarantocrasbasket.com/index.php?option=com_ninjarsssyndicator&feed_id=8&format=raw"];

    NSLog(@"You selected this: %@", [dataArray objectAtIndex: row]);
    NSLog(@"Ultime: %@", feedURL);

} }

最后点击UIPickerView的完成按钮:

-(void) categoriaSelezionata:(id)sender {

self.tableView.scrollEnabled = true;
categorie.enabled = YES;
[rect removeFromSuperview];
[pickerView removeFromSuperview];
[pickerviewToolbar removeFromSuperview];
[self refresh]; }

我调用函数“refresh”来解析新链接中的新项目,但应用程序崩溃了!

如果我放一个NSLog来查看链接是否正确,它也会崩溃。

Xcode错误是:

  

EXC_BAD_ACCESS(代码= 2,地址= 0xf)

为什么这不起作用?

0 个答案:

没有答案