我試圖讓用戶角色頁面從登錄中獲取數據。我創建了自己的委託函數來調用web服務,但由於 - [__ NSArrayM setRoleHistorys:]:無法識別的選擇器發送到實例,應用程序崩潰。 這裏是我的代碼:在.m文件:ios錯誤終止 - [__ NSArrayM setRoleHistorys:]:
- (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);
}
在委託文件
.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文件(代表)
#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,但該應用程序崩潰。
你能告訴我如何添加代碼? –
我不能告訴你需要做什麼。也許只是'UserRole * roles = [[UserRole alloc] init]'。目前還不清楚,因爲你沒有看到已經有一個,你沒有做很多與你試圖使用的(你不存儲它)... – Wain