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