こんにちは友人、iphoneで正規表現にcomponentsSeparatedByStringを与えるためにどのように
は、私がここに規制をしています私はすべてを作成し、私は、配列に格納しても、コンソールに私もグループに与えることを印刷しますが、私は与えるときcomponentsSeparatedByString
です私はこのmeassageをこのコード私のアプリケーションのクラッシュをやったとログメッセージの印刷を行うとき、私は間違っているところ、なぜ機能していない: -
[__NSCFArray componentsSeparatedByString:]: unrecognized selector sent to instance 0x4e283a0
2011-09-12 14:05:48.400 RegexKitLiteDemo[10576:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFArray componentsSeparatedByString:]: unrecognized selector sent to instance 0x4e283a0
これは私のコードは、いくつかのいずれかが正しい方向に私を助けてくださいです
-(void)sendRequest
{
// create the request
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.bookryanair.com/SkySales/FRSearch.aspx"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection) {
webData = [[NSMutableData data] retain];
NSLog(@"%@",webData);
} else {
// inform the user that the download could not be made
}
}
/// this for checking is that Sync is work or not
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[webData setLength: 0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[webData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
[connection release];
[webData release];
NSLog(@"Connection failed! Error - %@ %@",
[error localizedDescription],
[[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]);
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
loginStatus = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
[connection release];
NSString *regexString = @"Stations\\[""(.*)""\\] = new Station\\((.*)new Array\\((.*)\\)\\);";
matchArray = [loginStatus arrayOfCaptureComponentsMatchedByRegex:regexString];
NSLog(@"matchArray: %@", matchArray);
group = [[NSMutableArray alloc] initWithCapacity:[matchArray count]];
for (int i = 0; i < [matchArray count]; i++) {
NSString *temp = [[matchArray objectAtIndex: i] componentsSeparatedByString: @","];
[group addObject: temp];
NSLog(@"group: %@", group);
}
}
私は詳細を教えてくれます。私は適切なものが得られません。このコードを書く方法を知っている友人を助けてください。 – Rocky
確かな仲間です。この特定の行のエラーは、 'componentsSeparatedByString'の出力がNSStringではなくNSArrayであることです。これについての詳細はNSStringクラスのリファレンスを見てください。 – Madhu
NSArray * arr = [someString componentsSeparatedByString:@ "、"];コンポーネントSeperateByString関数がNSArrayオブジェクトを返すことを意味します@Madhuの説明はきちんとして清潔です。 –