私はこの問題を4日間近く処理しています。NSObjectからUIViewControllerへのデータの送信
私は、私のコードでそれほど問題ではないと思うが、問題を引き起こしているアプリケーションの構造だと思う。
私は1つのNSObject(クラス)からViewControllerに配列を取得するためのプロトコルとデリゲートを実装しようとしています。
私のコードだけの違いは、私がARCがオンになっている顔であるこのtutorialからコピーしたラインによって、かなり多くの行があるので、(強い)に(、非アトミック保持)を交換しなければならなかったとのdealloc :)
使用していませんだから、それはまだviewcontrollerにデータを戻さないと言われています。 (非常に迷惑な)私は何十ものさまざまな組み合わせのソリューションを試してきました。これは私のアプリケーションの構造や、初期化された方法などに誤りがあり、私が今説明しようとしていると信じさせてくれました。
私のパーサクラスのデリゲートと呼ばれるviewdidloadメソッドをtableviewでロードすると、tableviewの最初のセルがロードされ、接続クラスが呼び出され、サーバーからデータをダウンロードするように指示されます。 私の接続クラスの中で、アップルライブラリのNSURLConnectionデリゲートをdelegateメソッドのconnectionDidFinishLoadingで使用しています。ダウンロードされたデータはパーサクラスに渡されます(ただし、これはオブジェクトが再び宣言されるために間違っていると思います。これは私の接続クラスからパーサークラスを呼び出す方法です。データは私のパーサクラスになると
parserClass *myparser = [[EngineResponses alloc] init];
[myparser ReciveResponse:receivedData];
は、それが解析されますし、私は私のViewControllerの間でデータを渡すためにしようと..しかし、その私が設定しているデリゲートメソッドにアクセスすることはありません。
これはうまくいけば、どこに間違っているのか分からないためです。 あなたはどう思いますか?
UPDATE:HERESに私のコード -
ViewController.h
#import "EngineResponses.h" //delegates & protocols
interface SearchViewController : UITableViewController <PassParsedData> {
//delegates to parser class
EngineResponses *engineResponses;
//..
ViewController.m
#import "EngineResponses.h"
//this is where I set up the delegate/protocol for the parser class
- (void)viewDidLoad
{
[super viewDidLoad];
//..
engineResponses = [[EngineResponses alloc] init];
[engineResponses setMydelegate:self];
//..
}
//this is where i set up and call the connection class
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//..
if(indexPath.section == 0){
//..
if (indexPath.row == 0){
EngineRequests *engineRequests = [[EngineRequests alloc] init];
[engineRequests initalizePacketVariables:0 startCode:@"myReg" activationCode:@"myAct" methodName:@"GetStuff"];
//..
}
#pragma - Reciver methods
- (void)sendArray:(NSArray *)array
{
ICMfgFilterArray = array;
[self.tableView reloadData];
}
EngineRequests.m
//connection delegates etc..
//then I pass the data from the connection delegates over to the parser class
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
EngineResponses *engineResponses = [[EngineResponses alloc] init];
[engineResponses ReciveResponse:receivedData];
}
EngineResponses.h
@protocol PassParsedData
- (void)sendArray:(NSArray *)array;
@end
//..
id <PassParsedData> mydelegate;
//..
@property (strong) id <PassParsedData> mydelegate;
EngineResponses.m
- (void)parserDidEndDocument:(NSXMLParser *)parser
{
//..
[[self mydelegate]sendArray:filteredArray];
}
コードの編集されたバージョンは、散文の説明よりも診断しやすいでしょう。 –
um、あなたは '[myParser setDelegate:myViewController];'のようなことをしていますか?また、より良いソリューションを提案するには、実際にコードを参照する必要があります。 – ColdLogic
大丈夫、私は自分のコードを更新しました..申し訳ありませんが、それは長い時間がかかりました、私は完全にすべてを持っていることを確認した..だから私はエラーが私は2つの場所にパーサーオブジェクトを割り当てていると思う...しかし、これが正しいか、それを解決する方法を確認してください。 –