1

UITableViewのreloadDataメソッドに深刻な問題があります。UITableViewとNSMuttableArrayを含むUIViewControllerクラスWiGiMainViewControllerがあります。現在、AppDelegateでネットワーク呼び出しを発行しており、データがダウンロードされたらWiGiMainViewControllerに通知を投稿しています。通知のセレクターメソッドreloadWigiListで、最近ダウンロードされたアイテムを含むNSArrayを渡します。次に、渡された配列を使用してWiGiMainViewControllerのNSMuttableArrayを初期化し、UITableViewオブジェクトでreloadData()の呼び出しに進みます。nslogステートメントから、numberOfRowsInSectionはリロード時に起動されますが、cellForRowAtIndexPathでは起動されないため、UIは新しくダウンロードされたアイテムでUITableViewをリロードしないことがわかります。メインスレッドでreloadDataメソッドが呼び出されていること、およびデータソースデリゲートがIBで設定され、プログラムでWiGiMainViewControllerのviewDidLoadメソッドで設定されていることを確認しました。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;

}
4

2 に答える 2

0

私が最初にすることは、[self.wigiMainViewController.wigiListsreloadData]にブレークポイントを設定することです

wigiLists tableViewがデバッガーでnullを示している場合、それはおそらく設定されていないアウトレットです。また、デリゲートとデータソースの両方が設定されていることを確認してください。

于 2011-03-17T21:01:14.577 に答える
0

わお!この問題に頭をぶつけて3日後、それは途方もなく単純なものでした。WiGiMainViewControllerのViewDidLoadメソッドで、テーブルビューを初期化していました。

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

IBで作成したtableViewをインスタンスwigiListsにリンクしたため、ViewDidLoadで割り当てて初期化すると、IBで作成されて現在表示されているtableViewへのリンクが上書きされました。この行を取り除くと、すべてが修正されました。

于 2011-03-20T01:57:07.047 に答える