SQLite データベースからのデータを入力したい uipickerview があります。
appdelegate を介して変更可能な配列を介してデータにアクセスできますが、それをデータ ソースとして使用すると、uipicker の titleforrow セクションとして使用するとアプリがクラッシュします。
配列からのカウントは正しく、データは表示されません!
これが私のヘッダーファイルです:
@class OBMessage;
@interface LocationViewController : UIViewController <UITableViewDelegate, UIPickerViewDelegate, UIPickerViewDataSource, UITableViewDataSource, UIActionSheetDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate, MFMailComposeViewControllerDelegate, MFMessageComposeViewControllerDelegate> {
UITableViewCell *cell1;
UITableViewCell *cell2;
UITableViewCell *cell3;
UITableViewCell *cell4;
UITableViewCell *cell5;
UITableViewCell *cell6;
UITableViewCell *cell7;
UITableViewCell *cell8;
IBOutlet UILabel *addressLabel;
MKPlacemark *placemark;
IBOutlet UILabel *lLat;
IBOutlet UILabel *lLong;
IBOutlet UILabel *lHAcc;
IBOutlet UILabel *lAlt;
IBOutlet UILabel *lVAcc;
IBOutlet UILabel *lDate;
UIPickerView *singlePicker;
NSArray *pickerData;
NSString *pickedInfo;
DadsTaxiV2AppDelegate *appDelegate;
NSMutableArray *myarray;
}
@property (nonatomic, retain) IBOutlet UITableViewCell *cell1;
@property (nonatomic, retain) IBOutlet UITableViewCell *cell2;
@property (nonatomic, retain) IBOutlet UITableViewCell *cell3;
@property (nonatomic, retain) IBOutlet UITableViewCell *cell4;
@property (nonatomic, retain) IBOutlet UITableViewCell *cell5;
@property (nonatomic, retain) IBOutlet UITableViewCell *cell6;
@property (nonatomic, retain) IBOutlet UITableViewCell *cell7;
@property (nonatomic, retain) IBOutlet UITableViewCell *cell8;
@property (nonatomic, retain) IBOutlet UILabel *addressLabel;
@property (nonatomic, retain) IBOutlet UILabel *lLat;
@property (nonatomic, retain) IBOutlet UILabel *lLong;
@property (nonatomic, retain) IBOutlet UILabel *lHAcc;
@property (nonatomic, retain) IBOutlet UILabel *lAlt;
@property (nonatomic, retain) IBOutlet UILabel *lVAcc;
@property (nonatomic, retain) IBOutlet UILabel *lDate;
@property (nonatomic, retain) IBOutlet UIPickerView *singlePicker;
@property (nonatomic, retain) NSArray *pickerData;
@property (nonatomic, retain) NSString *pickedInfo;
@property (nonatomic, retain) NSMutableArray *myarray;
@property (nonatomic, retain) MKPlacemark *placemark;
-(IBAction)popupCameraSheet:(id)sender;
-(IBAction)popupMessageSheet:(id)sender;
-(void)showPicker;
@end
ここに私の m ファイルのビットがあります:
- (void)viewDidLoad {
[super viewDidLoad];
appDelegate = (DadsTaxiV2AppDelegate *)[[UIApplication sharedApplication] delegate];
self.myarray = appDelegate.messageArray;
}
-(void)showPicker
{
UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle:@"Select a Office Buddy Message to Include:"
delegate:self
cancelButtonTitle:@"Select" destructiveButtonTitle:@"Cancel"
otherButtonTitles:nil];
menu.tag = 4;
menu.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
singlePicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 185, 0, 0)];
singlePicker.delegate=self;
singlePicker.showsSelectionIndicator = YES;
[singlePicker selectedRowInComponent:0];
[singlePicker reloadComponent:0];
[menu addSubview:singlePicker];
[menu showInView:self.view];
[menu setBounds:CGRectMake(0, 0, 320, 700)];
[singlePicker release];
[menu release];
//NSInteger row = [singlePicker selectedRowInComponent:1];
//NSString *selected = [pickerData objectAtIndex:row];
//infoLabel.text = selected;
}
#pragma mark Picker Data Source Methods
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
//NSLog(@"[pickerData count]=%d",[pickerData count]);
//return [pickerData count];
NSLog(@"[messagearray count]=%d",[self.myarray count]);
//return [self.pickerData count];
return [self.myarray count];
}
#pragma mark Picker Delegate Methods
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
NSLog(@"[pickerData objectAtIndex:row]=%@",[self.myarray objectAtIndex:row]);
//return [self.pickerData objectAtIndex:row];
return [self.myarray objectAtIndex:row];
}
クラッシュログを忘れてすみません:
didSelectViewController:<LocationViewController: 0x9b7de90>
2012-09-07 20:43:07.142 OfficeBuddy[7300:c07] [messagearray count]=13
2012-09-07 20:43:07.142 OfficeBuddy[7300:c07] [messagearray count]=13
2012-09-07 20:43:07.142 OfficeBuddy[7300:c07] [pickerData objectAtIndex:row]=<OBMessage: 0x9a74ae0>
2012-09-07 20:43:07.143 OfficeBuddy[7300:c07] -[OBMessage isEqualToString:]: unrecognized selector sent to instance 0x9a74ae0
2012-09-07 20:43:07.144 OfficeBuddy[7300:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[OBMessage isEqualToString:]: unrecognized selector sent to instance 0x9a74ae0'
*** First throw call stack:
(0x1759022 0x1a5ecd6 0x175acbd 0x16bfed0 0x16bfcb2 0x8ed0ff 0xbcf17a 0x7a8bc0 0x847c54 0x8483ce 0x833cbd 0x83271a 0x83c220 0xbcf6bb 0x7a77ec 0x7a84f9 0x8ca1 0xcc71 0x83e5c5 0x83e7fa 0x47585d 0x172d936 0x172d3d7 0x1690790 0x168fd84 0x168fc9b 0x22847d8 0x228488a 0x7ad626 0x2f5d 0x2ed5)
terminate called throwing an exception(lldb)