我有一个严重的问题与UITableView
的reloadData
的方法。我有一个UIViewController
班,WiGiMainViewController
其中有UITableView
和NSMuttableArray
。我目前正在拨打AppDelegate
网络电话,并在数据下载完成后向WiGiMainViewController
发送通知。在我的通知reloadWigiList的选择器方法中,我传递了包含最近下载的项目的NSArray
。然后用传入的数组初始化WiGiMainViewController
的NSMuttableArray
,并继续在我的UITableView
对象上调用reloadData()
。我可以从NSLog
中看到numberOfRowsInSection
在重新加载时被触发,但不是cellForRowAtIndexPath
,因此导致UI不会用新下载的项目重新加载UITableView
。我已验证reloadData
方法正在主线程上调用,并且数据源委托在IB
中设置,并以编程方式在WiGiMainViewController的viewDidLoad方法中设置。任何想法为什么我的UITableView
,wigiLists没有重新加载数据,特别是没有调用cellForRowAtIndexPath
方法?UITableView不重装数据或调用cellForRowAtIndexPath
@interface WiGiMainViewController : UIViewController<FBRequestDelegate,UITableViewDelegate, UITableViewDataSource> {
//setup UI
UITableView *wigiLists;
WiGiAppDelegate *myAppDelegate;
NSMutableArray *itemsList;
}
@property (nonatomic, retain) WiGiAppDelegate *myAppDelegate;
@property (nonatomic, retain) IBOutlet UITableView *wigiLists;
@property (nonatomic, retain) NSMutableArray *itemsList;
-(void) reloadWigiList: (NSNotification*) notification;
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView;
-(NSInteger) tableView: (UITableView*) tableView numberOfRowsInSection:(NSInteger) section;
-(UITableViewCell *) tableView: (UITableView*)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath;
@end
@implementation WiGiMainViewController
@synthesize headerLabel = _headerLabel, userNameLabel = _userNameLabel, facebookPicture = _facebookPicture,
myAppDelegate, wigiLists, itemsList;
- (void)viewDidLoad {
NSLog(@"In viewDidLoad");
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadWigiList:) name:@"wigiItemUpdate" object:nil];
// get appdelicate
self.myAppDelegate = (WiGiAppDelegate*) [[UIApplication sharedApplication] delegate];
self.itemsList = [[NSMutableArray alloc] init];
//setup tableview
self.wigiLists = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
self.wigiLists.delegate = self;
self.wigiLists.dataSource = self;
//set up view
[self.headerLabel setText:self.myAppDelegate.HEADER_TEXT];
//check if user is logged in
if (self.myAppDelegate.isLoggedIn) {
//user is logged in
NSLog(@"HERE");
//get facebook information to populate view
[self retrieveFacebookInfoForUser];
//[self.myAppDelegate retrieveWigiItems];
}else {
//user is not logged in
NSLog(@"user not logged in");
//show login modal
}
//[self.wigiLists reloadData];
[super viewDidLoad];
}
-(void) reloadWigiList: (NSNotification *) notification {
if ([NSThread isMainThread]) {
NSLog(@"main thread");
}else{
NSLog(@"METHOD NOT CALLED ON MAIN THREAD!");
}
NSLog(@"notification recieved:%@", notification.userInfo);
NSLog(@"in reloadwigilists:%@", wigiLists);
NSLog(@"list size:%@", self.itemsList);
NSLog(@"delegate:%@",self.wigiLists.delegate);
NSLog(@"datasource:%@",self.wigiLists.dataSource);
//populate previously empty itemsList
[self.itemsList setArray:notification.userInfo];
NSLog(@"list size:%@", self.itemsList);
[self.wigiLists reloadData];
}
/////////////////////////////////////
// UITableViewDelegate protocols
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
//NSLog(@"numberofsections: %@", [self.itemsList count]);
return 1;
}
-(NSInteger) tableView: (UITableView *)tableView numberOfRowsInSection:(NSInteger) section {
NSLog(@"7t87giuiu%@",self.itemsList);
NSLog(@"numberofrows: %i", [self.itemsList count]);
return [self.itemsList count];
//return 6;
}
很高兴听到您解决您的问题。继续并接受你的回答让其他人知道。 – raidfive 2011-03-20 03:02:01