我被困在一個愚蠢的問題,因爲兩天。我有UITableViewController
推入Navigation Controller
。當它加載,因爲沒有數據,所以空表可見:UITableviewcontroller中的UITableview - cellforrowatindexpath在調用時未被調用
但是,當我收到來自服務器的數據,並調用[self.tableView reloadData]
,既numberOfRowsInSection
和heightForRowAtIndexPath
得到調用除了cellForRowAtIndexPath
,我的控制器顯示無表:
我真的不能明白爲什麼它正在發生。除了cellForRowAtIndexPath
之外,所有數據源方法都被調用。請人指導我...謝謝..
ActLogController.h
@interface ActLogController : UITableViewController<ASIHTTPRequestDelegate,UITableViewDataSource,UITableViewDelegate>
@property(strong) NSMutableArray *activityKeys;
@end
ActLogController.m
- (void)viewDidLoad
{
[super viewDidLoad];
activityKeys = [[NSMutableArray alloc] init];
self.tableView.dataSource = self;
}
-(void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self retrieveActivityLogFromServer];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return activityKeys.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...
ActivityLogUnit *act = [activityKeys objectAtIndex:indexPath.row];
cell.textLabel.text = act.price;
return cell;
}
-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 50.0;
}
-(void) requestFinished:(ASIHTTPRequest *)request
{
NSArray *list = [request.responseString JSONValue];
for (int i = 0; i < list.count; i++) {
NSArray *singleTrade = [[list objectAtIndex:i] JSONValue];
ActivityLogUnit *unit = [[ActivityLogUnit alloc] init];
unit.symbol = [singleTrade objectAtIndex:0];
unit.type = [singleTrade objectAtIndex:1];
unit.price = [singleTrade objectAtIndex:2];
unit.volTraded = [singleTrade objectAtIndex:3];
unit.remVol = [singleTrade objectAtIndex:4];
unit.actualVol = [singleTrade objectAtIndex:5];
unit.recordID = [singleTrade objectAtIndex:6];
unit.orderNo = [singleTrade objectAtIndex:7];
unit.time = [singleTrade objectAtIndex:8];
[activityKeys addObject:unit];
}
if(activityKeys.count > 0)
{
[self.tableView reloadData];//it is called and I have got 6 items confirm
}
}
編輯
我設置一些虛擬數據在我的陣列activityKeys
,Da ta被顯示在表格中,並且cellforrowatindexpath
被成功調用。但隨着我在某段時間後重新加載數據,其他方法被調用,除了這一個,表格消失,如第二張圖所示。有任何想法嗎?
你有IBOutlet中連接了的tableView? –
在numberOfRowsInSection中記錄activityKeys.count以查看它返回的內容。 – rdelmar
@Bhargavi我沒有得到我的tableviewcontroller的xib文件。 – NightFury