UITableView не перезагружает данные или не вызывает cellForRowAtIndexPath - PullRequest
0 голосов
/ 19 марта 2011

У меня серьезная проблема с методом UITableView reloadData.У меня есть класс UIViewController, WiGiMainViewController, в котором есть UITableView и NSMuttableArray.В настоящее время я выполняю сетевые вызовы на AppDelegate и отправляю уведомления на WiGiMainViewController после загрузки данных.В моем методе выбора для уведомления, reloadWigiList, я передаю NSArray, содержащий недавно загруженные элементы.Затем я инициализирую WiGiMainViewController s NSMuttableArray переданным массивом и перехожу к вызову reloadData() для моего UITableView объекта.Из операторов NSLog видно, что numberOfRowsInSection запускается при перезагрузке, но не cellForRowAtIndexPath, поэтому пользовательский интерфейс НЕ перезагружает UITableView с недавно загруженными элементами.Я убедился, что метод reloadData вызывается в основном потоке и что делегат источника данных установлен в IB и программно в методе viewDidLoad WiGiMainViewController.Есть идеи, почему мои UITableView, wigiLists не перезагружают данные, в частности, не вызывают метод 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;

 }

1 Ответ

2 голосов
/ 20 марта 2011

Вау!после 3 дней удара головой об эту проблему, это было что-то смехотворно простое.В моем методе ViewDidLoad в WiGiMainViewController я инициализировал свое табличное представление:

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

Поскольку я связал созданный в IB табличный вид с моим экземпляром wigiLists, alloc'ing и инициализация в ViewDidLoad перезаписали мою ссылку наtableView создан в IB и в данный момент отображается.Избавление от этой строки исправило все.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...