1

在我的应用程序中,我将“提要链接”加载到 tableView 中。它运作良好。但现在我需要使用UIPickerView.

在我viewDidLoad有这个代码用于将提要项加载到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];

使用此代码,我UIPickerViewUIBarButtonItem导航栏上调用:

- (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];
}

Now when one row of UIPIckerView is selected I do this:

-(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]; }

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

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

Xcode 错误是:

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

为什么这不起作用?

4

0 回答 0