2011-03-19 101 views
0

我有一个严重的问题与UITableViewreloadData的方法。我有一个UIViewController班,WiGiMainViewController其中有UITableViewNSMuttableArray。我目前正在拨打AppDelegate网络电话,并在数据下载完成后向WiGiMainViewController发送通知。在我的通知reloadWigiList的选择器方法中,我传递了包含最近下载的项目的NSArray。然后用传入的数组初始化WiGiMainViewControllerNSMuttableArray,并继续在我的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; 

} 

回答

2

哇!经过3天的反对这个问题,我觉得这简直太荒唐了。在WiGiMainViewController我viewDidLoad方法,我是初始化我的tableview:

self.wigiLists = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain]; 

因为我已经挂了的tableView我在IB创建我的实例wigiLists,alloc'ing并在viewDidLoad中初始化改写我的链接的tableView创建在IB中并且当前正在显示。摆脱这条线固定了一切。

+1

很高兴听到您解决您的问题。继续并接受你的回答让其他人知道。 – raidfive 2011-03-20 03:02:01

相关问题