Ios 在另一个void方法问题中调用NSString
我试图将NSSting调用到一个void方法中,但我遇到了EXC\u BAD\u访问错误。这是什么原因造成的 我已在btnPickerDoneTouchHandler中对NSLog进行了制动点(调试),但choiceList为空 .H:Ios 在另一个void方法问题中调用NSString,ios,nsstring,uipickerview,Ios,Nsstring,Uipickerview,我试图将NSSting调用到一个void方法中,但我遇到了EXC\u BAD\u访问错误。这是什么原因造成的 我已在btnPickerDoneTouchHandler中对NSLog进行了制动点(调试),但choiceList为空 .H: @interface controlView : UIViewController{ NSString *choiceList; } -(NSInteger)numberOfComponentsInPickerView:(UIPickerView
@interface controlView : UIViewController{
NSString *choiceList;
}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 1;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
return [res count];
}
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
return [[res objectAtIndex:row]objectForKey:@"choice_name"];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
choiceList = [NSString stringWithFormat:@"<r_PM act='closepos_choice' cl_choice='%d'/>", row];
NSLog(@"You have selected row %@", choiceList);
}
- (void)btnPickerDoneTouchHandler{
//I have put here the brakepoint.
NSLog(@"choiceList is %@", choiceList);
}
.M:
@interface controlView : UIViewController{
NSString *choiceList;
}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 1;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
return [res count];
}
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
return [[res objectAtIndex:row]objectForKey:@"choice_name"];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
choiceList = [NSString stringWithFormat:@"<r_PM act='closepos_choice' cl_choice='%d'/>", row];
NSLog(@"You have selected row %@", choiceList);
}
- (void)btnPickerDoneTouchHandler{
//I have put here the brakepoint.
NSLog(@"choiceList is %@", choiceList);
}
-(NSInteger)组件编号pickerView:(UIPickerView*)pickerView{
返回1;
}
-(NSInteger)pickerView:(UIPickerView*)pickerView行数组件:(NSInteger)组件{
返回[res count];
}
-(NSString*)pickerView:(UIPickerView*)pickerView标题箭头:(NSInteger)组件行:(NSInteger)组件{
return[[res objectAtIndex:row]objectForKey:@“choice_name”];
}
-(void)pickerView:(UIPickerView*)pickerView didSelectRow:(NSInteger)row不完整项:(NSInteger)组件
{
choiceList=[NSString stringWithFormat:@',行];
NSLog(@“您已选择行%@”,choiceList);
}
-(无效)BTNPickerDoneTouch处理程序{
//我已经把制动点放在这里了。
NSLog(@“唱诗班成员为%@”,唱诗班成员);
}
您可以执行以下操作:
.H:
.M:
您可以执行以下操作: .H: .M:
只需在.h文件中创建一个@property,如下所示:
@property (strong, nonatomic) NSString * choiceList;
只需在.h文件中创建一个@property,如下所示:
@property (strong, nonatomic) NSString * choiceList;
试试这个-
在您的.h文件中
@property (strong, nonatomic) NSString * choiceList;
在你的.m文件中
@synthesize choiceList;
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
self.choiceList = [NSString stringWithFormat:@"<r_PM act='closepos_choice' cl_choice='%d'/>", row];
NSLog(@"You have selected row %@", self.choiceList);
}
- (void)btnPickerDoneTouchHandler{
//I have put here the brakepoint.
NSLog(@"choiceList is %@", self.choiceList);
}
@综合唱诗班;
-(void)pickerView:(UIPickerView*)pickerView didSelectRow:(NSInteger)row不完整项:(NSInteger)组件
{
self.choiceList=[NSString stringWithFormat:@',行];
NSLog(@“您已选择行%@”,self.choiceList);
}
-(无效)BTNPickerDoneTouch处理程序{
//我已经把制动点放在这里了。
NSLog(@“唱诗班成员为%@”,self.choiceList);
}
试试这个-
在您的.h文件中
@property (strong, nonatomic) NSString * choiceList;
在你的.m文件中
@synthesize choiceList;
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
self.choiceList = [NSString stringWithFormat:@"<r_PM act='closepos_choice' cl_choice='%d'/>", row];
NSLog(@"You have selected row %@", self.choiceList);
}
- (void)btnPickerDoneTouchHandler{
//I have put here the brakepoint.
NSLog(@"choiceList is %@", self.choiceList);
}
@综合唱诗班;
-(void)pickerView:(UIPickerView*)pickerView didSelectRow:(NSInteger)row不完整项:(NSInteger)组件
{
self.choiceList=[NSString stringWithFormat:@',行];
NSLog(@“您已选择行%@”,self.choiceList);
}
-(无效)BTNPickerDoneTouch处理程序{
//我已经把制动点放在这里了。
NSLog(@“唱诗班成员为%@”,self.choiceList);
}
您是否使用ARC或手动内存管理?如果您没有使用ARC,则为choiceList字符串生成属性和合成。不,我没有使用ARC,即使您使用ARC,使用属性而不是ivars是更好的做法。我使用了属性和合成,但仍然会给我EXC\u BAD\u访问错误。您使用ARC或手动内存吗管理?如果您没有使用ARC,则为choiceList字符串生成属性和合成。不,我没有使用ARC,即使您使用ARC,使用属性而不是ivars是更好的做法。我使用了属性和合成,但仍然会给我EXC_BAD_访问错误。