ios 错误终止 -[__NSArrayM setRoleHistorys :]:

标签 ios objective-c web-services

我正在尝试创建从登录中获取数据的用户角色页面。我创建了自己的委托(delegate)函数来调用 web 服务,但应用程序因 [__NSArrayM setRoleHistorys:]: 无法识别的选择器发送到实例而崩溃。 这是我的代码:在 .m 文件中:

- (void)parserDidStartDocument:(NSXMLParser *)parser
{
  nodeContent = [[NSMutableString alloc]init];
}

- (void)parserDidEndDocument:(NSXMLParser *)parser
{
  arrayitems = [[NSMutableArray alloc] init];
U serRoleDataParser *userroleParser = [[UserRoleDataParser alloc] init];
  // UserRole *currentStudent = (UserRole *) arrayitems;
NSString *Username = username.text;
NSLog(@"the String value%@",Username);
[userroleParser getUserHistoryForIndex:0 LoginId:username.text];
 NSLog(@"the String user value %@",username.text);
userroleParser.delegate = self;

}
- (void) didrecieveData : (NSArray *) userHistories forIndex :(int) index
 {
arrayitems = [[NSMutableArray alloc] init];
UserRole *roles = (UserRole *) arrayitems;
roles.RoleHistorys = userHistories;
datadisplay.text = roles.role;
NSLog(@"the Success data%@", datadisplay.text);

}

在委托(delegate)文件.h中

 @interface UserRole : NSObject

@property (nonatomic,copy)  NSString *username;
 @property (nonatomic,copy)  NSString *role;
@property (nonatomic,copy)  NSString *empcode;

@property (nonatomic,copy)NSMutableArray * RoleHistorys;
@end

Dataparser.h 文件(委托(delegate))

#import <Foundation/Foundation.h>
 #import "UserRole.h"

 @protocol UserRoleDataParserDelegate <NSObject>

 - (void) didrecieveData : (NSArray *) userHistories forIndex :(int) index ;

 @end

 @interface UserRoleDataParser : NSObject<NSXMLParserDelegate>
{
 NSMutableData *xmlData;
NSXMLParser *userroleParser;
NSMutableString *capturedString;
BOOL captureCharacters;
NSMutableArray *userHistories;
}

- (void) getUserHistoryForIndex : (int) index LoginId :(NSString*) loginId;

 @property (weak,nonatomic) id <UserRoleDataParserDelegate> delegate;
 @property (nonatomic) int index;

@end

正在 nslog 中获取输出,但应用程序崩溃了。

最佳答案

此代码不正确:

arrayitems = [[NSMutableArray alloc] init];
UserRole *roles = (UserRole *) arrayitems;

您不能仅将数组转换为自定义类类型(除非您已子类化 NSMutableArray 并且该实例实际上属于子类类型)。在尝试使用它之前,您需要创建一个实例或找到所需的正确实例。

关于ios 错误终止 -[__NSArrayM setRoleHistorys :]:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22609678/

相关文章:

ios - 使用 convertToWorldSpaceAR 翻译 CCNode 时遇到问题

iOS 模拟器不显示 Xcode 6.3 的内容

android - 无限滚动 ListView - 在构建期间调用 setState() 或 markNeedsBuild

javascript - 没有 WKScriptMessage 的 WKWebView 回调

objective-c - 导航栏设置为不可见,但单击后退按钮时会出现

android - 如何在android中解析一个SoapObject

web-services - JAX-WS 客户端 |发送带有安全 header 的客户端请求

java - 限制对 Amazon EC2 上的 Web 服务的访问

ios - 查看 EkReminder 重复频率的最佳方式?

ios - 视频在 UITableViewCell 中不必要地开始