Ios xcode-pickerview未在非arc模式下显示
我正在尝试使用一个关闭了ARC的PickerView,它已经变成了一个夜猫子,如果有人能快速查看,我将非常感激。请提前建议如何解决…thnx 问题是,我的应用程序的其余部分是非arc的,所以我想添加pickerview作为一个类,可以在项目中作为viewcontroller运行。。。 4天前,我有多个选择器在使用arc时工作得很好,但当我关闭arc时,它变成了一场噩梦…为了确定确切的问题,我已经删除了所有的装饰,现在只处理一个裸露的结构…没有错误,但数组中的数据没有显示…我列出了头文件和补充文件下面…我链接文件夹的原因是为了使接口文件可用…以便也可以检查连接…但我们可以在第一次检查基本代码后查看…非常感谢您的关注和时间 HIos xcode-pickerview未在非arc模式下显示,ios,arrays,xcode,Ios,Arrays,Xcode,我正在尝试使用一个关闭了ARC的PickerView,它已经变成了一个夜猫子,如果有人能快速查看,我将非常感激。请提前建议如何解决…thnx 问题是,我的应用程序的其余部分是非arc的,所以我想添加pickerview作为一个类,可以在项目中作为viewcontroller运行。。。 4天前,我有多个选择器在使用arc时工作得很好,但当我关闭arc时,它变成了一场噩梦…为了确定确切的问题,我已经删除了所有的装饰,现在只处理一个裸露的结构…没有错误,但数组中的数据没有显示…我列出了头文件和补充文件
我将等待你的答复
[无法访问评论,因此我在此处回复]感谢rdelmar,我注释掉了init bundle和按钮的子视图,但是现在构建提供了错误的访问权限…我大致知道发生了什么,但不知道如何解决它…问题基本上是数组没有保留用于objectAtIndex调用…需要某种方式保留它…thnx这是一种不好的态度显示整个项目的链接。尝试以更具描述性的方式显示问题。并定义不清楚的代码部分!寻求调试帮助的问题(“为什么这段代码不起作用?”)必须包括所需的行为、特定的问题或错误以及在问题本身中重现它所需的最短代码。没有明确问题陈述的问题对其他读者没有用处。请看:。对此表示抱歉,实际上我已经在stackoverflow网站上用尽了所有答案,这就是为什么我想保持简短,这不是缺乏态度,而是经过许多小时的尝试后感到疲惫,而且感觉这一定是我错过的一件小事……是initWithNibName:bundle:被调用吗?看起来您正在隐藏和取消隐藏选择器,我认为您已将其添加到xib或故事板中的控制器中,因此不应将其作为button方法中的子视图添加。另外,确保你的按钮与它的动作相连接,因为在你触摸按钮之前你不应该看到选择器。
#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