我正在尝试使用带有ARC的PickerView关闭,它已成为一个夜晚,如果有人可以请快速看看,请提出如何解决... thnx提前将非常感激 问题是我的应用程序的其余部分是非弧形的,因此我想将pickerview添加为可以作为项目中的viewcontroller运行的类... 4天前,我有多个采摘工具精美地工作但是当我关闭电弧时,它变成了一场噩梦...找出确切的问题我已经删除了所有的装饰,现在只是使用裸露的结构....有没有错误,但数组中的数据没有显示...我列出下面的标题和实现文件...我链接文件夹的原因是使接口文件可用....这样连接可以是检查过......但是我们可以在首次检查基本代码后查看...非常感谢您的关注和时间......
#import <UIKit/UIKit.h>
@interface HomeViewController : UIViewController UIPickerViewDataSource,UIPickerViewDelegate>
{NSArray *categoryTypes;
}
@property (retain, nonatomic) IBOutlet UIPickerView *categoryTypePicker;
@property (retain, nonatomic) IBOutlet UIButton *categoryTypeBtn;
#import "HomeViewController.h"
@interface HomeViewController ()
#define kPICKER1COLUMN 1
#define kCATEGORYTYPEPICKERTAG 21
#define kCATEGORYTYPEBTN 31
@end
@implementation HomeViewController
@synthesize categoryTypeBtn;
@synthesize categoryTypePicker;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
categoryTypes = [[NSArray alloc] initWithObjects:@"Appetizers",@"Breakfast",@"Dessert",@"Drinks",
@"Main Dish/Entree", @"Salad", @"Side Dish", @"Soup", @"Snack",
@"Baby Food", @"Pet Food", nil];
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
categoryTypePicker.tag = kCATEGORYTYPEPICKERTAG;
categoryTypePicker.showsSelectionIndicator = TRUE;
categoryTypePicker.dataSource = self;
categoryTypePicker.delegate = self;
self.categoryTypePicker.dataSource = self;
self.categoryTypePicker.delegate = self;
[self.categoryTypePicker reloadAllComponents];
categoryTypePicker.hidden = YES;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (int)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
if (pickerView.tag == kCATEGORYTYPEPICKERTAG)
return kPICKER1COLUMN;
else { return 0; }
}
- (int)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
if (pickerView.tag == kCATEGORYTYPEPICKERTAG)
return [categoryTypes count];
else { return 0; }
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
if (pickerView.tag == kCATEGORYTYPEPICKERTAG)
return [categoryTypes objectAtIndex:row];
else { return 0; }
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if (pickerView.tag == kCATEGORYTYPEPICKERTAG)
{
NSString *categoryType = [categoryTypes objectAtIndex:[categoryTypePicker selectedRowInComponent:0]];
[categoryTypeBtn setTitle:categoryType forState:UIControlStateNormal];
NSLog(@"%@", categoryType);
}
pickerView.hidden=YES;
}
-(IBAction) showCategoryTypePicker{
{
[self.view addSubview:categoryTypePicker];
categoryTypePicker.hidden = NO;
}
}
- (void)viewDidUnload {
[super viewDidUnload];
}
- (void)dealloc {
[categoryTypes release];
[categoryTypePicker release];
[super dealloc];
}
@end
我将等待你的回复...
答案 0 :(得分:1)
[无法访问评论,所以我在这里回复]感谢rdelmar我注释掉了init-bundle和按钮的子视图,但现在构建给错误提供了错误的访问...我对这是什么有一个粗略的想法继续,但不知道如何解决它...问题基本上是没有为objectAtIndex调用保留数组...需要一些方法来保留它... thnx