不叫上reloadData UITableView的數據源的方法,我在這個問題上幾個小時stucked,並沒有發現,因此任何解決方案...在IOS
我有一個表作爲一個子視圖中UIViewController
。當加載視圖時,所有數據源方法都會調用tableview
,但是當我從服務器接收數據並調用[someTable reloadData]
時,不會調用任何數據源方法。我已經通過斷點確認我的數組包含100個對象。代理和數據源都綁定到IB中的File owner
。
什麼可能丟失?請幫我...謝謝:(
OutLogController.h
@interface OutLogController : UIViewController<UITableViewDataSource,UITableViewDelegate,ASIHTTPRequestDelegate>
{
NSMutableArray *outstandingKeys;
}
@property (strong, nonatomic) IBOutlet UITableView *someTable;
@end
OutLogController.m
@interface OutLogController()
@end
@implementation OutLogController
@synthesize someTable;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
outstandingKeys = [[NSMutableArray alloc] init];
someTable = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
someTable.rowHeight = 85;
[self retrieveOutstandingLogFromServer];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return outstandingKeys.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
LogUnit *unit = [outstandingKeys objectAtIndex:indexPath.row];
cell.textLabel.text = unit.symbol;
return cell;
}
-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 85;
}
-(void) requestFinished:(ASIHTTPRequest *)request
{
NSLog(@"%@",request.responseString);
NSArray *list = [request.responseString JSONValue];//contains 100 objects
for (int i = 0; i < list.count; i++) {
NSArray *singleTrade = [[list objectAtIndex:i] JSONValue];
LogUnit *unit = [[LogUnit alloc] init];
unit.symbol = [singleTrade objectAtIndex:0];
unit.type = [singleTrade objectAtIndex:1];
unit.price = [singleTrade objectAtIndex:2];
unit.remaining = [singleTrade objectAtIndex:3];
unit.order = [singleTrade objectAtIndex:4];
unit.time = [singleTrade objectAtIndex:5];
[outstandingKeys addObject:unit];
}
if(outstandingKeys.count > 0)
{
[someTable reloadData];//does reload table
}
}
編輯
脫離線後:
種someTable = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
數據源方法被稱爲除了cellForRowAtIndexPath
和表從視圖中消失,因爲這種方法不被調用。任何想法爲什麼它不能被稱爲?
注意:我已經確認我有計數= 100後從服務器響應。
someTable是一個IBoutlet,所以你應該把它連接到XIB的桌子上你有沒有連接它 –
@Divz是的它是..! – NightFury
someTable = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain]; –