//HomeVIEwController.h#import <UIKit/UIKit.h>#import "tableController.h"@interface HomeVIEwController : UIVIEwController { IBOutlet UItableVIEw *table; tableController *tableController;}@end
和
//HomeVIEwController.m#import "HomeVIEwController.h"@interface HomeVIEwController ()@end@implementation HomeVIEwController- (voID)vIEwDIDLoad{ [super vIEwDIDLoad]; tableController = [[tableController alloc] init]; table.dataSource = tableController.tableSource.dataSource; table.delegate = tableController.tableSource.delegate; [tableController loadtable]; // HERE I CALL LOADtable FROM tableCONTRolLER CLASS TO PARSE DATA AND POPulATE UItableVIEW [table reloadData];}
和
// tableController.h#import <UIKit/UIKit.h>@interface tableController : NSObject <UItableVIEwDelegate,UItableVIEwDataSource> { UItableVIEw *tableSource; // a lot of NSMutableArray to parse my data}- (voID)loadtable;@property (nonatomic,strong) UItableVIEw *tableSource;@end
和
//tableController.m#import "tableController.h"#import "AFNetworking.h"@interface tableController ()@end@implementation tableController@synthesize tableSource;- (voID)loadtable { NSURL *parseURL = // remote URL to parse Data NSURLRequest *request = [NSURLRequest requestWithURL:parseURL]; AFJsONRequestoperation *parSEOperation = [AFJsONRequestoperation JsONRequestoperationWithRequest:request success:^(NSURLRequest *request,NShttpURLResponse *response,ID JsON) { // code to parse Data and NSLog to test operation [tableSource reloadData]; [tableSource setUserInteractionEnabled:YES]; [tableSource scrollRectToVisible:CGRectMake(0,1,1) animated:YES]; } failure:^(NSURLRequest *request,NSError *error,ID JsON) { NSLog(@"%@",[error userInfo]); }]; [parSEOperation start]; [tableSource setUserInteractionEnabled:NO];}
而且,显然,仍然在tableController.m中,所有经典的UItableVIEw委托方法:
- (NSInteger)numberOfSectionsIntableVIEw:(UItableVIEw *)tableVIEw {// my code}- (NSInteger)tableVIEw:(UItableVIEw *)tableVIEw numberOfRowsInSection:(NSInteger)section {// my code}- (CGfloat)tableVIEw:(UItableVIEw *)tableVIEw heightForRowAtIndexPath:(NSIndexPath *)indexPath {// my code}- (UIVIEw *)tableVIEw:(UItableVIEw *)tableVIEw vIEwForheaderInSection:(NSInteger)section {// my code}- (UItableVIEwCell *)tableVIEw:(UItableVIEw *)tableVIEw cellForRowAtIndexPath:(NSIndexPath *)indexPath{// my code}- (voID)tableVIEw:(UItableVIEw *)tableVIEw willdisplayCell:(UItableVIEwCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {// my code}- (voID)tableVIEw:(UItableVIEw *)tableVIEw dIDSelectRowAtIndexPath:(NSIndexPath *)indexPath {// my code}
好吧,解析是完美的(我可以用NSLog测试它),但我的表是空的.你能帮我吗?
编辑:在我的代码中,loadtable解析方法是异步的,所以表加载了正确的数据源和委托但是在解析所有数据之前;实际上如果我设置了一个固定的numberOfRows然后SCRolL table我可以看到填充的所有行.但是,当我加载HomeVIEwController时,*表仍然是EMPTY.
解决方法 从哪里/如何在tableController中设置UItableVIEw * tableSource对象?还尝试在主线程中重新加载tablevIEw.
编辑
在HomeController vIEwDIDLoad中更改这些
table.dataSource = tableController.tableSource.dataSource; table.delegate = tableController.tableSource.delegate;
至
table.dataSource = tableController; table.delegate = tableController;
同时将HomeController类设置为tableController&的委托.一旦得到回复.在HomeController中调用一个方法来重新加载tablevIEw(在主线程中)!
为此,首先在tableController .h文件中创建一个属性父类
@property(nonatomic,retain) ID parent;
然后将HomeController设置为HomeController vIEwDIDLoad中的委托
tableController.parent = self.
一旦你在完成块调用中得到响应,
[self.parent reloadtableVIEw]; // reloadtableVIEw将是HomeController中具有[self.table reloadData]的函数.
希望这能解决问题.
总结以上是内存溢出为你收集整理的objective-c – 解析后在单独的类中的UITableView委托和数据源全部内容,希望文章能够帮你解决objective-c – 解析后在单独的类中的UITableView委托和数据源所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)