2011-03-19 3 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를 초기화 한 다음있는 tableView 생성에 alloc'ing하고있는 viewDidLoad에 초기화, 내가있는 tableView를 연결했기 때문에

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

내가 내 인스턴스 wigiLists에 IB에서 만든 내 링크를 덮어 IB에서 현재 표시되고 있습니다. 이 선을 제거하면 모든 것이 해결되었습니다.

+1

질문에 대답 해 주셔서 감사합니다. 다른 사람들이 알 수 있도록 대답을 수락하십시오. – raidfive

관련 문제